PHP code example of wtfz / laravel-route-button
1. Go to this page and download the library: Download wtfz/laravel-route-button library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wtfz / laravel-route-button example snippets
php artisan vendor:publish --tag=laravel-route-button
// resources/views/vendor/route-button
use Wtfz\LaravelRouteButton\RouteButton;
class YourModel extends Model
{
use RouteButton;
// init empty route button
public static $routeButton = [];
// or init global route button
public static $routeButton = [
[
'route' => 'admin.auth.user.delete',
'text' => 'Delete User',
'view' => 'frontend.profile.confirm',
'args' => [$this, 1], // Optional, default: $model
],
// ...
];
// or init named route button
public static $routeButton = [
'index' => [
'route' => 'admin.auth.user.edit',
'text' => 'Edit User'
],
'edit' => [
'route' => 'admin.auth.user.destroy',
'text' => 'Destroy User'
],
// ...
];
// or init mixed route button
public static $routeButton = [
[
'route' => 'admin.auth.user.edit',
'text' => 'Edit User',
'args' => [$this, 1], // Optional, default: $model
],
'index' => [
'route' => 'admin.auth.user.edit',
'text' => 'Edit User'
],
'edit' => [
'route' => 'admin.auth.user.destroy',
'text' => 'Destroy User'
],
// ...
];
}
// global route button
{{ $model->routeButton() }}
// named route button
{{ $model->routeButton('edit') }}
// or in Livewire table...
Column::make(__('Actions'), 'id')
->format(function ($value, $row, $column) {
return $row->routeButton('edit');
}),
// or add new route button on the fly...
Column::make(__('Actions'), 'id')
->format(function ($value, $row, $column) {
// for global route (set integer index)
$row::$routeButton[0][] = [
'route' => 'admin.auth.user.delete',
'text' => 'Delete User',
'args' => ['type' => 'member', 'user' => $row],
];
// for named route (set string index)
$row::$routeButton['edit'][] = [
'route' => 'admin.auth.user.delete',
'text' => 'Delete User',
'args' => ['type' => 'member', 'user' => $row],
];
return $row->routeButton('index');
}),