我遇到了一个问题,当我尝试在创建用户时附加school_id时,我得到NULL
值。学校与用户有很多关系。
这是我的UserController商店功能:
public function store(Request $request)
{
$user->school_id = $request->school_id;
$user = User::create($request->all());
$user->attachRole(Role::where('id', $request->role)->first());
return redirect()->route('user.index');
}
查看:
<div class="form-group">
<select class="form-control" name="school_id" required>
<option disabled selected>Vælg skole</option>
@foreach ($schools as $school)
<option value="{{ $school->id }}">{{ $school->name }}</option>
@endforeach
</select>
</div>