I would like to know how to create a template on the blade containing the generic actions (view, edit, delete) for all the routes of my application, for example in the actions column 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 the 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 single button template and avoid repeating code and be able to control the policies in just one file.
For example, create an acoesTemplate.blade.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 do not know how to implement the variables in the routes.