Laravel Missing required parameters for [Route: pharmacy-detail] [URI: pharmacy / {slug}]

1

I get this error when trying to call a route

    <a href="{{ route('farmacia-detail', $medicamento->slug) }}" class="btn btn-primary">Detalle</a>
cuando el llamado a ella en:
    @foreach ($medicamentos as $medicamento)
        <div class="col-sm">
          <div class="card text-center" style="width: 18rem; margin-top: 70px">
            <img style="height: 100px; width: 100px; backgroup-color: #EFEFEF; margin: 20px;" class="card-img-top
            rounded-circle mx-auto d-block"src="images/{{$medicamento->avatar}}" alt="">
            <div class="card-body">
              <h5 class="card-title">{{$medicamento->medicamento}}</h5>
              <p class="card-text">{{$medicamento->descripcion}}</p>
              <p class="card-text">{{$medicamento->laboraorio}}</p>
              <h3><span class="label label-success">${{$medicamento->precio,2}}</span></h3>
              <a href="#" class="btn btn-warning"><i class="fa fa-cart-plus"></i>Add to Cart</a>
              <a href="{{ route('farmacia-detail', $medicamento->slug) }}" class="btn btn-primary">Detalle</a>
            </div>
          </div>
        </div>
    @endforeach

When I call pharmacy-detail

my routes are:

    Route::get('/', function () {
    return view('welcome');
});

Route::resource('usuario','UsuarioController');
Route::resource('medicamentos','MedicamentosController');
Route::resource('farmacia','FarmaciaController');
Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

Route::get('farmacia/{slug}',[
  'as' => 'farmacia-detail',
  'uses' => 'FarmaciaController@show'
]);
// carrito
Route::get('cart/show',[
  'as'=> 'cart-show',
  'uses' => 'CartController@show'
]);

Route::get('cart/add/{farmacia}',[
  'as'=> 'cart-add',
  'uses' => 'CartController@add'
]);

the controller

  public function index(Request $request)
    {
        $medicamentos=Medicamento::medicamento($request->get('medicamento'))->orderBy('medicamento','DESC')->paginate();
        return view('medicamentos.index',compact('medicamentos'));
    }
  public function show($slug)
    {
        $medicamento=Medicamento::where('slug', $slug)->first();
        dd($medicamento);
    }
    
asked by Wilmer Fabian Bermudez 30.12.2018 в 21:42
source

1 answer

0

With the information that shows there can be several causes of the error:

  • Conflict with the route generated by the resourceful route .

    The possible solutions in this case are:

    a. Define the path farmacia-detail before Route::resource('farmacia',...); in the routes file.

    b. Exclude path 'show' from resource:

    Route::resource('farmacia',...)->except(['show']);

  • It is possible that there is some conflict with the routes stored in the cache, or that it does not appear there simply, for this you have to clean the route cache and verify in detail the list of artisan routes, even in cases more extreme, there may be some additional cache linked to PHP or the server.

  • That the helper route does not take the value correctly (although this depends on the version of Laravel that you use). The solution would be to pass the parameter as an array instead of a single value: route('farmacia-detail', [$medicamento->slug]);

  • answered by 31.12.2018 в 05:28