Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel casts pivot table

<?php
 
namespace AppModels;
 
use IlluminateDatabaseEloquentModel;
 
class Role extends Model
{
    /**
     * The users that belong to the role.
     */
    public function users()
    {
        return $this->belongsToMany(User::class)->using(RoleUser::class);
    }
}
/**
*When defining the RoleUser model, you should extend the 
IlluminateDatabaseEloquentRelationsPivot
*/
<?php
 
namespace AppModels;
 
use IlluminateDatabaseEloquentRelationsPivot;
 
class RoleUser extends Pivot
{
    //
}
Source by laravel.com #
 
PREVIOUS NEXT
Tagged: #laravel #casts #pivot #table
ADD COMMENT
Topic
Name
5+2 =