在用户创建上附加关系(Laravel 5.4)

时间:2017-05-05 16:14:50

标签: php laravel eloquent laravel-5.4

我遇到了一个问题,当我尝试在创建用户时附加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>

0 个答案:

没有答案