I am trying to store route id of a review (it contains restaurant id) in a variable called restaurant_id
in a reviews table. This is the store function:
public function store(Request $request) {
if (! Auth::check()) {
return redirect('/index');
}
$review = new Review;
$review->user_id = auth()->user()->id;
$review->restaurant_id = $request->route('id');
$review->value = $request->input('value');
$review->save();
}
This is the link on the restaurant profile that directs to the review template Add review
. This is the action on the form:
{!!Form::open(['action' => ['ReviewsController@store'], 'method'=>'POST', 'enctype'=>'multipart/form-data'])!!}
This is review template:
<html>
{!!Form::open(['action' => ['ReviewsController@store',], 'method'=>'POST', 'enctype'=>'multipart/form-data'])!!}
<div class="form-group">
{{Form::textarea('value', null, ['id'=>'value', 'placeholder'=>'Insert here', 'name'=>'value'])}}
</div>
{{Form::submit('submit', ['class'=>'btn btn-primary', 'type'=>'submit', 'id'=>'submit'])}}
{!!Form::close()!!}
</html>
I get the error below when submitting:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'restaurant_id' cannot be null (SQL: insert into reviews (user_id, restaurant_id, value, updated_at, created_at) values (1, ?, kkkkbkb, 2019-07-11 08:39:10, 2019-07-11 08:39:10))
$request->route('id')
value? – akaincoreid
for the restaraunt? You're attempting to grab it from the route in theRequest
object but dont appear to be setting it. – PeppermintologyForm::open(['action' => ['ReviewsController@store', $restaurant_id], ...
– akaincore