如何将数据从刀片文件传递到Laravel中的Controller

时间:2016-08-11 17:04:10

标签: php laravel-5

我需要将刀片文件中的输入数据传递给控制器​​文件刀片文件输入fiels

<input type="number" id="cid" name="cid"  />{{ $collaborator->user()->first()->id}}</input>

我需要将以上数据添加到我的控制器addPermission函数中以将其保存在表

public function addPermission(Request $request, $id,  Permission $permission)
{
     $this->validate($request, [
        'status'   => 'required'
    ]);

    $permission = new Permission;

    $permission->status = $request->input('status');
    $permission->project_id       = $id;
    $permission->save();
    return redirect()->back()->with('info','Permission has been added to your Collaborator successfully');
}
你可以给我一个想法吗?

1 个答案:

答案 0 :(得分:0)

<input type="number" id="cid" name="cid"  />{{ $collaborator->user()->first()->id}}</input>

应该是

<input type="number" id="cid" name="cid" value="{{ $collaborator->user()->first()->id }}" />

然后您可以像处理状态一样访问它

$permission->collaborator_id = $request->input('cid');

但正确的方法是使用员工(一对多)或附加(多对多)

$permission->collaborator()->associate(Collaborator::findOrFail($request->input('cid')));