laravel 5.1 プロジェクトに entrust パッケージをインストールしました。このパッケージはこちらEntrust Package Githubにあります。サインアップ投稿ボタンの後にユーザーに役割を割り当てたいと思います。その後、各ユーザーは異なるプロファイルを完了するためです。上記の AuthController.php を見ることができます。
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller{
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
protected $redirectPath = '/';
protected $loginPath = '/';
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'getLogout']);
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
'role' => 'required|',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'role' => $data['role'],
]);
$tutorschoolRole = DB::table('roles')->where('name', '=', 'Φροντιστήριο')->pluck('id');
$studentRole = DB::table('roles')->where('name', '=', 'Μαθητής')->pluck('id');
$teacherRole = DB::table('roles')->where('name', '=', 'Καθηγητής')->pluck('id');
$parentRole = DB::table('roles')->where('name', '=', 'Γονέας')->pluck('id');
if(User::role == "Φροντιστήριο"){
User::roles()->attach($tutorschoolRole);
}
if(User::role == "Μαθητής"){
User::roles()->attach($studentRole);
}
if(User::role == "Καθηγητής"){
User::roles()->attach($teacherRole);
}
if(User::role == "Γονέας"){
User::roles()->attach($parentRole);
}
}
}