0
當我DD每個變量我可以看到值,包括user_id 它只是不會存儲在數據庫...我不知道是什麼導致這.. 。無法在表單提交時通過Auth :: user() - > id
{!! Form::open(['method'=>'POST', 'action'=>'[email protected]']) !!}
<div class="form-group">
{!! Form::hidden('post_id', $post->id, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::hidden('user_id', $value = Auth::id(), ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::textarea('body', null, ['class'=>'form-control', 'rows'=> 2]) !!}
</div>
<br>
<div class="form-group">
{!! Form::submit('Submit Comment', ['class'=>'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
控制器::
public function store(Request $request)
{
$data = [
'post_id' => $request->post_id,
'user_id' => $request->user_id,
'body' => $request->body
];
Comment::create($data);
return redirect()->back();
}
DB:
userd_id總是與0值查看存儲
在您的控制器中,您可以合併'$ request-> all()'上的用戶標識。這也是一個更安全的解決方案,只是隱藏表單域 – SuperDJ
執行'dd(Auth :: user())'並檢查加載頁面 – Vikash
問題需要澄清的結果是什麼。 –