I have tried using join table in laravel
role_user table has the roles_id and the user_id column roles table has the id and the name of the role users table has the id and the name of the user
$roles = Role::leftJoin('role_user', 'roles.id', '!=' , 'role_user.role_id')
->select('roles.*', 'role_user.user_id', 'role_user.role_id')
->where('role_user.user_id','=',$name)
->get();
But it seems that '!='
is not working I have tried using the '='
and it's just working fine
When im trying to use the '='
there are no results
I have also tried
public function roles()
{
return $this->belongsToMany('App\Role');
}
@foreach($user->roles as $role)
{{ roles->name}}
@endForeach
But it displays the matching id of user_role and role table, I want to do the opposite i want to display the role table's rows that do not match the user_role's table
I want to display the role table's rows that do not match the user_role
table
Use whereDoesntHave()
method:
$roles = Role::whereDoesntHave('users', function($q) use($name) {
$q->where('name', $name);
})->get();
In the view:
@foreach ($roles as $role)
{{ role->name }}
@endforeach
Don't forget to define users()
relationship:
public function users()
{
return $this->belongsToMany('App\User');
}
In your User Model create function roles
Role::whereNotIn('id',function($query){
$query->select('role_id')->from('role_user');
})->get();
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
I have downloaded mysql ZIP from here https://devmysql
When running my Wordpress UpdraftPlus database restore script I get the error Error Code: 1067Invalid default value for 'user_registered'