graffislife's avatar

Missing required parameters for [Route: ] [URI: store/{id}].

My Controller

public function shows($id) { $inventories = Inventory::find($id); return view('inventory.show')->with('inventories', $inventories);

    }
    public function showRate(Request $request)
    {   
        //create rating
        $ratings = new Rating;
        $ratings->rating = $request->input('rating');
        $ratings->inv_id = inventory()->id;
        $ratings->user_id = auth()->user()->id;
        $ratings->save();

        return redirect('/store')->with('success','Rating updated');
    }

my route

Route::post('/store/{id}','InventoryController@showRate'); Route::get('/store/{id}',['uses' =>'InventoryController@shows','as' => 'shows']);

my view

                <h2>{{$inventories->name}}</h2>
                {{--  <img class="card-img-top img-fluid" width="500" height="500" src="/storage/design_image/{{$inventory->design_image}}" alt="">  --}}
                    <br><hr>
                <table class="table table-striped">
                    <tr>
                        <th>ID</th>
                        <th>{{$inventories->id}}</th>
                    </tr>
                    <tr>
                        <th>Name</th>
                        <th>{{$inventories->name}}</th>
                    </tr>
                    <tr>
                        <th>Price</th>
                        <th>₱{{$inventories->price}}</th>
                    </tr>
                    <tr>
                        <th>Owner</th>
                        @if($inventories->user_id > 0)
                        <th>{{$inventories->user->fname}} {{$inventories->user->lname}}</th>  
                        @else
                        <th> Admin </th>
                        @endif                
                    </tr><br>
                    {!!Form::open(['action'=>'InventoryController@showRate', 'method'=>'POST'])!!}
                    {{--  {!! Form::open(array('route' => array('account.show', $result->id))) !!}  --}}
                    {{--  action('UserController@update', ['id' => $user->id])  --}}
                    <div class="form-group">
                        {{Form::label('rating','Rating')}}<br>
                        {{Form::select('rating', ['1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5'], null, ['placeholder' => 'Select rating'])}}  
                    </div>                                    
                    {!! Form::close()!!}  

I am new to laravel. I am hoping to put a form inside a "show" page. Please help me and elaborate it so that I can understand. Thank you! :)

PS. I'm using laravel collective.

0 likes
1 reply
Sergiu17's avatar
Sergiu17
Best Answer
Level 60

web.php

Route::post('/store/{id}','InventoryController@store')->name('inventory.store'); 

Route::get('/store/{id}', 'InventoryController@show')->name('inventory.show');

InventoryController.php

public function show($id) 
{ 
    $inventories = Inventory::find($id); 
    
    return view('inventory.show')->with('inventories', $inventories);
}
 
public function store(Request $request, $id)
{   
    $ratings = new Rating;
    $ratings->rating = $request->input('rating');
    $ratings->inv_id = $id;
    $ratings->user_id = auth()->user()->id;
    $ratings->save();

    return redirect('/store')->with('success','Rating updated');
}

inventory.show

<form action="{{ route('inventory.store', ['id' => $inventory->id])  }}" method='post'>
    <div class='form-group'>
        <select name='rating'>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
        </select>
    </div>
</form>                           

I didn't test, hope it works

4 likes

Please or to participate in this conversation.