codewiser / laravel
Packages I might include to every Laravel application
v1.1.8
2025-02-05 12:12 UTC
Requires
- php: ^8.1
- cerbero/enum: ^2.1
- codewiser/dadata: ^1.0
- codewiser/http-cache-control: ^2.0
- codewiser/intl: ^1.0
- codewiser/laravel-cast-datetime-tz: ^1.0
- codewiser/laravel-make: ^1.0
- codewiser/laravel-meilisearch: ^1.0
- codewiser/laravel-notifications: ^1.0
- codewiser/laravel-scout: ^1.0
- codewiser/laravel-sendsay-mailer: ^1.0
- codewiser/laravel-smscenter-mailer: ^1.0
- codewiser/socialiteprovider: ^1.0
- codewiser/telegram-channel: ^1.0
- codewiser/workflow: ^4.4
Requires (Dev)
- phpunit/phpunit: ^11.4
README
Packages I might include to every Laravel application
Structures
Structure is an array
or json
attributes with structured interface.
For example:
use Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Database\Eloquent\Casts\AsStringable; use Illuminate\Support\Stringable; /** * @property null|Stringable $first_name * @property null|Stringable $second_name * @property null|Stringable $family_name */ class Username extends Pivot { protected function casts(): array { return [ 'first_name' => AsStringable::class, 'second_name' => AsStringable::class, 'family_name' => AsStringable::class, ]; } }
Apply Username
struct to User
model:
use Illuminate\Database\Eloquent\Model; use Codewiser\Database\Eloquent\Casts\AsStruct; /** * @property null|Username $name */ class User extends Model { protected function casts(): array { return [ 'name' => AsStruct::using(Username::class) ]; } }
You can make it not-nullable:
use Illuminate\Database\Eloquent\Model; use Codewiser\Database\Eloquent\Casts\AsStruct; /** * @property Username $name */ class User extends Model { protected function casts(): array { return [ 'name' => AsStruct::using(Username::class, required: true) ]; } }
Structure collections
The same way, you may cast collections of custom structs:
use Codewiser\Database\Eloquent\Casts\AsStructCollection; use \Illuminate\Support\Collection; /** * @property null|Collection<Contact> $contacts_1 * @property null|ContactCollection<Contact> $contacts_2 * @property Collection<Contact> $contacts_3 */ class User extends Model { protected function casts(): array { return [ 'contacts_1' => AsStructCollection::using(Contact::class), 'contacts_2' => AsStructCollection::using(ContactCollection::class, Contact::class), 'contacts_3' => AsStructCollection::using(Contact::class, required: true), ]; } }
Passive SoftDeletes
PassiveSoftDeletes
traits works alike SoftDeletes
, but it is disabled by
default.
Also, it counts record as trashed only then deleted_at
is reached. So you
may trash records in perspective.
It comes with \Codewiser\Database\Eloquent\Traits\HasDeletedAt
trait,
that is applicable to custom builders with the same behavior.