0
votes

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))

1
what is your $request->route('id') value?akaincore
Where/how are you passing the id for the restaraunt? You're attempting to grab it from the route in the Request object but dont appear to be setting it.Peppermintology
check your restaurant_id column and define it null. maybe the id is not getting any variable value and you are trying to store it. probably, the restaurant_id is define not nullJulius Fasema
You probably should set form action like this Form::open(['action' => ['ReviewsController@store', $restaurant_id], ...akaincore
@IncOre am getting the error Undefined variable: restaurant_id (View: C:\xampp\htdocs\restaurantFinder\resources\views\restaurants\review.blade.php)user11071523

1 Answers

0
votes

where do you get this value? $request->route('id');. the restaurant_id is not seeing this $request->route('id');