You know you could have the roles in the users table as well.
Aug 15, 2016
2
Level 2
Laravel multiple table
Hello there!, I have following 3 tables 1. User 2.Profile 3. Permission The question is how can i get result from these tables ? I want to check user permission in View For ex: User has a profile which is Admin, admin have permission according to permission table which means configure permission dynamically
User Model
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
public function profiles()
{
return $this->belongsTo('App\Profile');
}
}
Profile
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Profile extends Model
{
public function users()
{
return $this->hasMany('App\User');
}
public function permissions()
{
return $this->hasMany('App\Permission');
}
}
Permission
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Permission extends Model
{
public function profiles()
{
return $this->belongsTo('App\Profile');
}
}
Please or to participate in this conversation.