Laravel.io
//Код формы
<div class="row">
<div class="col-md-12">
<div class="ibox float-e-margins">
<div class="ibox-content p-md">
<form class="m-t" role="form" action="/register" method="POST" class="form-horizontal" name="_token" value="{{ csrf_token() }}">
{{ csrf_field() }}
<div class="form-group">
<label for="email">
Email:
</label>
<input type="email" name="email" class="form-control" placeholder="Введите Ваш Email">
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="role"> ФИО: </label>
<input type="text" name="name" class="form-control" placeholder="Введите ФИО">
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="company_id"> Компания: </label>
<select name="company_id" class="form-control">
<option disabled selected>Выберите компанию</option>
@foreach($companys as $company)
<option value="{{$company->id}}">{{$company->name}}</option>
@endforeach
</select>
</div>
<div class="col-lg-12">
<div class="ibox">
<div class="ibox-title" style="border-width: 1px 0 0;">
<h5>Устройства</h5>
</div>
<div class="ibox-content">
<p>
Выберите устройства для пользователя.
</p>
<select name="device_id" class="form-control dual_select" multiple>
@foreach($dv as $device)
<option value="{{$device->id}}">{{$device->device}}</option>
@endforeach
</select>
</div>
</div>
</div>
<button type="submit" class="btn btn-primary">Сохранить</button>
<input type="hidden" name="user_token" id="tk_qd">
</form>
//Контроллер
public function register()
{
if(Sentinel::check()){
$companys = Company::where('user_id', Sentinel::getUser()->id)->get();
$dv = Device::where('user_id', Sentinel::getUser()->id)->get();
$hom = House::where('user_id', Sentinel::getUser()->id)->get();
$ass = Access::where('user_id', Sentinel::getUser()->id)->get();
$asc = Apartament::where('user_id', Sentinel::getUser()->id)->get();
}else{
$hom = House::get();
$companys = Company::get();
$dv = Device::get();
$ass = Access::get();
$asc = Apartament::get();
}
return view('auth.reg',compact('companys','hom','dv','ass','asc'));
}
public function postRegister(Request $request)
{
$token = str_random(32);
$grand = [
'name' => request('name'),
'email' => request('email'),
'password' => request('password'),
'user_token' => ($token),
];
$user = Sentinel::registerandActivate($grand);
$rolechosen = ($request->input('role'));
//Присвоение ролей
$admin_role = Sentinel::findRoleBySlug('admin');
$manager_role = Sentinel::findRoleBySlug('manager');
$user_role = Sentinel::findRoleBySlug('user');
if ($rolechosen == 'admin') {
$admin_role->users()->attach($user);
} elseif ($rolechosen == 'manager') {
$manager_role->users()->attach($user);
} elseif($rolechosen == 'user') {
$user_role->users()->attach($user);
}
// dd($request->all());
return redirect('/profile');
}