0

I have a generic table.blade.php that manage the build of a table based on the model collection given.

How can I, for example, build the edit link foreach items with the right controller.

Example:

<!-- stored in /resources/views/includes/table.blade.php -->

all table....

<tbody>
@foreach( $items as $model )
 <tr><td>    
 <a href="{{ route( '****.edit', $model ) }}">Edit</a>
 </td></tr>
@endforeach
</tbody>

where **** should be the correct controller for the model.

Mindexperiment
  • 145
  • 1
  • 10
  • Will it give you more flexibility if you handle it in the controller? Thus allowing your logic in the controller to choose which model to interact with and return what you need (data/view/etc) . – jeremykenedy Oct 01 '18 at 00:28
  • the table is rendered with the ModelController@index action. – Mindexperiment Oct 01 '18 at 08:23

2 Answers2

0

In routes/web.php:

Route::get('some-link/{model}', 'EntityController@edit')->name('****.edit');

Or in view can use action() helper:

{{ action('EntityController@edit', $params) }}

0

Why don't you pass the controller name from the controller and it shall be rendered to the desired route.

<a href="{{ route( $controllerName.'.edit', $model ) }}">Edit</a>

You can pass variables from controllers using compact()