سلام من سه تا جدول دارم به نام های زیر
جدول user
جدولrole
id---types
read-----10
20------write
جدولroleuser
id---user_id---role_id
10-----20-----1
20------20----2
اینم مدل هر قسمت
class Role extends Model
{
protected $fillable = [
'id', 'types',
];
public function roleuser(){
return $this->belongsTo('AppRoleuser');
}
}
class Roleuser extends Model
{
protected $fillable = [
'role_id', 'user_id', 'active',
];
public function user(){
return $this->hasOne('AppUser');
}
public function role(){
return $this->hasMany('AppRole');
}
}
class User extends Authenticatable
{
public function roleuser(){
return $this->belongsTo('AppRoleuser');
}
}
کد کنترلر جهت واکشی نقش هر کاربر و نمایش در جدول
$roles=Roleuser::all();
return view('admin.role.maneger',compact('roles'));
کد نمایش view
@foreach($roles as $role)
{{ $role->role->types }}
@endforeach
میخواستم بدونم باید چیکار کنم تا داده ها رو نشون بده در view
شاید هم استباه تعریف کردم رابطه هارو
خطای زیر رو بهم میده
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'roles.roleuser_id' in 'where clause' (SQL: select * from `roles` where `roles`.`roleuser_id` = 24 and `roles`.`roleuser_id` is not null) (View: C:\laragon\www\lan-hospital\resources\views\admin\role\maneger.blade.php)درواقع من مدل سوم رو باید داشته باشم برای کنترل کاربرام
در حالت عادی وقتی کاربر ثبت نام می مکند
جدول رول یوز به صورت زیر میشه
id----user_id-----role_id----active
0---------1---------5-------1
جدول فوق میگه که کاربر 5نقش شماره یک غیرفعال هست
حالا نقش یک مثلن ایجاد مقاله هست و صفر یعینی غیرفعال هست
شاید پاسخ شما همینجا باشد