Reputation: 35
I have one link as below:
<a href='{{ route('transferDelete', $tran->transfer_id) }}'><i class='far fa-trash-alt'></i></a>
It gets parsed by the following route:
Route::get('delete/{transfer_id}', [TransferController::class, 'destroy'])->name('transferDelete');
But the destroy method in the TransferController class is empty. On the other hand, the second parameter gets the correct ID (as expected):
public function destroy(Transfer $transfer, $bla)
{
//$transfer behaves like: $transfer = new Transfer;
//$bla is a real id.
}
Is there a way to make $transfer be pointing to transfer_id=$bla, without explicitly doing a Transfer::find($bla)?
Upvotes: 0
Views: 59
Reputation: 50481
You need to match the route parameter name to the name of the typehinted parameter of the Controller method if you want Implicit Route Model Binding to take place:
v
Route::get('delete/{transfer}', ...);
v
public function destroy(Transfer $transfer, $bla)
Upvotes: 1