1. Go to this page and download the library: Download codewiser/laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
codewiser / laravel example snippets
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,
];
}
}
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)
];
}
}
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,
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,
use Illuminate\Database\Eloquent\Builder;
use Codewiser\Database\Eloquent\Traits\HasPivot;
class BookBuilder extends Builder
{
use HasPivot;
}
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
Book::query()->whereHasMany('authors', fn(BelongsToMany $builder) => $builder
->wherePivot('role', 'author')
->where('name', 'Edgar Allan Poe')
);