Category : relation

I’m creating a authorization management system . but, when creating a new user, by assigning a role to the user, user-related permissions are not given,I want to automatically grant the user permission when assigning a new user by assigning a role. Controller: public function store(UserCreateRequest $request) { $data = $request->all(); $user = User::create($data); if ($user ..

Read more

I’m creating a authorization management system . but, when creating a new user, by assigning a role to the user, user-related permissions are not given,I want to automatically grant the user permission when assigning a new user by assigning a role. Controller: public function store(UserCreateRequest $request) { $data = $request->all(); $user = User::create($data); if ($user ..

Read more

I’m learning eloquent relationship on Laravel and i got question on the hasonethrough by using the same table design as Laravel’s docs tables mechanics (id, name) cars (id, model, mechanic_id) owners (id, name, car_id) then I define the relationship at the mechanic model to access car owner class Mechanic extends Model { public function carOwner() ..

Read more

I have simple question. How could I write a Factory that let me defines relationships that use make() or create() depending on original call make() or create()? It is my use case: I have a simple factory /** @var $factory IlluminateDatabaseEloquentFactory */ $factory->define(AppUser::class, function (Faker $faker) { return [ ‘role_id’ => factory(Role::class), ‘name’ => $faker->name, ..

Read more