有谁能告诉我如何从数据库中恢复用户的角色? 知道我有3个表(用户,角色,User_role) 迁移:
表用户:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
表格角色:
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('description');
$table->timestamps();
});
}
表user_role:
public function up()
{
Schema::create('user_role', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->integer('role_id');
$table->timestamps();
});
}
我的控制器中返回用户列表的函数是membrevis():
public function membrevis()
{
$filter = isset($_GET['filter']) ? $_GET['filter'] : null;
$query = DB::table('users')
->join('user_role', 'users.id', '=', 'user_role.user_id')
->join('roles', 'user_role.role_id', '=', 'roles.id')
->where('users.valid','=',1)
->select('users.*','roles.description');
if ($filter != null) {
$query->where('users.name','like','%'.$filter.'%')
->orWhere('roles.description','like','%'.$filter.'%');
}
$itemsPerPage = 8 ;
$currentPage = isset( $_GET['page'] ) && is_numeric( $_GET['page'] ) ? $_GET['page'] : 1;
$urlPattern = '/membre2?page=(:num)';
$totalItems = $query->count();
$donner = $query->offset( ( $currentPage - 1 ) * $itemsPerPage )->limit( $itemsPerPage )->get();
$paginator = new Paginator( $totalItems, $itemsPerPage, $currentPage, $urlPattern );
return view('membre2',['users'=> $donner,'paginator'=> $paginator]);
}
我可以在这里修改什么来恢复用户的角色?