0
I would like to know how to create a template in the Blade containing generic actions (view, edit, delete) for all routes of my application, for example in the column of actions I have the code:
<td>
<!-- botão Exibir -->
<a href="{{ route('admin.cores.show',[$cor->id]) }}" class="@lang('global.button.fields.exibir')">@lang('global.app_show')
</a>
<!-- botão Editar -->
<a href="{{ route('admin.cores.edit',[$cor->id]) }}" class="@lang('global.button.fields.editar')">@lang('global.app_edit')
</a>
<!-- botão Apagar -->
{!! Form::open(array(
'style' => 'display: inline-block;',
'method' => 'DELETE',
'onsubmit' => "return confirm('".trans("global.app_are_you_sure")."');",
'route' => ['admin.cores.destroy', $cor->id])) !!}
{!! Form::submit(trans('global.app_delete'), array('class' => trans('global.button.fields.apagar'))) !!}
{!! Form::close() !!}
</td>
The route of view:
Route::group(['middleware' => ['auth'], 'prefix' => 'admin', 'as' => 'admin.'], function () {
//Usuários e Permissões
Route::resource('users', 'Admin\UsersController');
Route::post('users_mass_destroy', ['uses' => 'Admin\UsersController@massDestroy', 'as' => 'users.mass_destroy']);
});
My idea would be to create a unique template for the buttons and avoid repeating codes and be able to control the directives in just one file.
For example, create a php file with the following lines:
<a href="{{ route($routeKey.'.show', $row->id) }}" class="@lang('global.button.fields.exibir')">@lang('global.app_show')</a>
<a href="{{ route($routeKey.'.edit', $row->id) }}" class="@lang('global.button.fields.editar')">@lang('global.app_edit')</a>
{!! Form::open(array(
'style' => 'display: inline-block;',
'method' => 'DELETE',
'onsubmit' => "return confirm('".trans("global.app_are_you_sure")."');",
'route' => [$routeKey.'.destroy', $row->id])) !!}
{!! Form::submit(trans('global.app_delete'), array('class' => 'btn btn-xs btn-danger')) !!}
{!! Form::close() !!}
And then just call this file in the display columns, but I don’t know how to implement the variables in the routes.
Perfect, saved a lot of code repetition so. Thank you!
– Rafael Meirim