Home > Enterprise >  My "href" does not direct me to my route with double parameter - Laravel
My "href" does not direct me to my route with double parameter - Laravel

Time:02-22

I have a button where I have to return the customer id and the id of the payments made to a specific payment

<a
  href="{{ route('clients-credits-abono', ['clientid' => $client->id, 'creditid' => $creditclient->id]) }}"
  
>
  View Pays
</a>

now, I have two routes, the first route shows me all the credits that belong to a client, in the second I show the payments made to the credit selected on the button.

Route::get('/clients/{clientid}/credits', [ClientCreditController::class, 'show'])->name('clients-credits-index');
Route::get('/clients/{clientid}/credits/{creditid}', [ClientPayController::class, 'show'])->name('clients-credits-abono');

but when I click the button I get an error:

Property [id] does not exist on this collection instance.

if I put a number in the URL (test.test/clients/1/credits/4) it shows me the view

I want to assume that the error is when capturing the second parameter, since $client does give me the ID, but $creditid does not.

thanks in advance :D

CodePudding user response:

You probably have a collection in your $client variable or $creditclient variable. Can you check them at the code below? You probably use ->get() at the end of your Eloquent chain so it will return you a collection.

<a href="{{route('clients-credits-abono', ['clientid' => $client->id, 'creditid' => $creditclient->id])}}" >View Pays</a>

You can read more here.

CodePudding user response:

href have no problem.

Property [id] does not exist on this collection instance.
this mean your object $client or $creditclient have no property id pls check following step :

  1. check with dd() your above objects
  2. check your controller that $client and $creditclient are compacted?
  • Related