How do I send any parameter via href and receive in the Resource controller in Laravel?

Asked

Viewed 50 times

1

I made a screen that will have a button to view and another to edit, but the href on the button I have {{route('products.index', 'E')}} my route is so:

Route::resource('products', 'ProductController');

my controller is like this:

 public function index()
    {
        $url_segment = \Request::segment(2);
        dd($url_segment);

        $products = Product::latest()->paginate(5);

        return view('products.index', compact('products'))
                ->with('i', (request()->input('page', 1) -1)* 5);
    }

in the view that returns in the above method you have to check the parameter sent by href of the first view.

example:

@if($parametro == 'E')
    mostrar o botão de editar
@else
    não mostra
@endif

as you can see I tried the segment but it’s not working out as I would in the controller?

Obs: no return on dd($url_segment); brings me null.

What I want to do is just retrieve the href parameter in the Resource controller in the index method

but when I try to receive

public funcion index($id)
{
    dd($id);
}

returns me the error below:

Too few Arguments to Function App Http Controllers Productcontroller::index(), 0 passed and Exactly 1 expected.

  • Why don’t you make an exception with, except in your route file so you can recreate the route .index passing argument? It’s just a suggestion.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.