PHP code example of inlayphp / actions
1. Go to this page and download the library: Download inlayphp/actions 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/ */
inlayphp / actions example snippets
use Inlay\Actions\Action;
use Inlay\Actions\ActionModal;
$archive = Action::make('archive')
->label('Archive customer')
->url('/admin/customers/{id}/archive')
->method('post')
->color('warning')
->icon('archive-box')
->data(['notify' => true])
->modal(
ActionModal::make('Archive this customer?')
->description('The customer can be restored later.')
->submitLabel('Archive')
->cancelLabel('Keep customer')
->icon('archive-box', 'warning')
->width('lg')
->alignment('center'),
);
use Inlay\Actions\BulkAction;
$delete = BulkAction::make('delete')
->url('/admin/customers/bulk-delete')
->method('delete')
->color('danger')
->
Action::make('publish')
->label(fn (): string => $post->underReview() ? 'Send for review' : 'Publish')
->color(fn (): string => $post->underReview() ? 'warning' : 'primary')
->icon(fn (Action $action): string => 'icon-'.$action->name());
use Inlay\Actions\Action;
use Inlay\Actions\Enums\ActionSize;
use Inlay\Actions\Enums\IconPosition;
Action::make('edit')
->label('Edit customer')
->icon('pencil')
->iconPosition(IconPosition::After)
->size(ActionSize::Small)
->outlined()
->tooltip('Edit this customer')
->badge(3)
->badgeColor('warning')
->keyBindings(['mod+e', 'shift+f2']);
Action::make('docs')->url('/docs')->link();
Action::make('refresh')
->icon('arrow-path')
->iconButton()
->tooltip('Refresh');
Action::make('status')
->label('Needs review')
->badge(); // badge-shaped trigger
Action::make('download-report')
->url('/reports/monthly.csv')
->download();
Action::make('edit-customer')
->form([
// ...
])
->slideOver()
->modalWidth('xl')
->stickyModalHeader()
->stickyModalFooter();
Action::make('create-user')
->form([
// ...
])
->modalSubmitAction(fn (Action $action): Action => $action
->label('Save user')
->icon('check'))
->modalCancelAction(fn (Action $action): Action => $action
->label('Keep editing')
->outlined())
->extraModalFooterActions(fn (Action $action): array => [
$action
->makeModalSubmitAction('save-and-create-another', [
'createAnother' => true,
])
->label('Save and create another')
->outlined(),
Action::make('send-welcome-email')
->label('Send welcome email separately')
->modal(
ActionModal::make('Send a welcome email?')
->description('This child action has its own confirmation and lifecycle.'),
)
->authorizeUsing(
fn (Request $request, User $record): bool =>
$request->user()->can('email', $record),
)
->action(fn (User $record) => SendWelcomeEmail::dispatch($record))
->cancelParentActions(),
])
->action(function (array $data, array $arguments): array {
$user = User::create($data);
return [
'user' => $user->getKey(),
'createAnother' => $arguments['createAnother'] ?? false,
];
});
Action::make('finish-review')
->cancelParentActions('edit-user');
Action::make('delete-user')
->instanceKey('users.10.delete');
use App\Models\Post;
use Illuminate\Http\Request;
use Inlay\Actions\Action;
use Inlay\Actions\ActionModal;
Action::make('publish')
->modal(
ActionModal::make('Publish this post?')
->description('Readers will see the post immediately.')
->submitLabel('Publish'),
)
->authorizeUsing(
fn (Request $request, Post $record): bool =>
$request->user()?->can('publish', $record) === true,
)
->rules([
'note' => ['nullable', 'string', 'max:500'],
])
->beforeFormValidated(fn (array $data) => audit('publish.validating', $data))
->afterFormValidated(fn (array $data) => audit('publish.validated', $data))
->mutateFormDataUsing(fn (array $data): array => [
...$data,
'published_by' => auth()->id(),
])
->before(fn (Post $record) => audit('publish.started', $record))
->databaseTransaction()
->action(function (Post $record, array $data): array {
$record->update([
'published_at' => now(),
'published_by' => $data['published_by'],
]);
return ['id' => $record->getKey()];
})
->after(fn (Post $record) => event(new PostPublished($record)))
->failure(fn (Throwable $exception) => report($exception))
->successNotificationTitle('Post published.');
->before(function (Action $action, Post $record): void {
if (! $record->team->subscribed()) {
$action->halt('Upgrade the team plan before publishing.');
}
})
protected function table(Table $table): Table
{
return $table->actions([
Action::make('archive')
->t->user()?->can('archive', $record) === true,
)
->databaseTransaction()
->action(fn (Customer $record) => $record->update(['archived' => true])),
]);
}
BulkAction::make('archive')
->minimumSelection(2)
->maximumSelection(100)
->deselectRecordsAfterCompletion();
use Inlay\Actions\ActionGroup;
ActionGroup::make([
BulkAction::make('approve'),
BulkAction::make('reject')->color('danger'),
])
->label('Change status')
->icon('ellipsis-horizontal')
->iconButton()
->size('small')
->tooltip('More bulk actions')
->badge(2)
->badgeColor('info')
->keyBindings('mod+shift+m')
->dropdownPlacement('top-end')
->dropdownWidth('md');
ActionGroup::make('more', [
ActionGroup::make('publishing', [
BulkAction::make('publish'),
BulkAction::make('schedule'),
])
->label('Publishing')
->dropdown(false),
ActionGroup::make('danger-zone', [
BulkAction::make('archive'),
BulkAction::make('delete')->color('danger'),
])
->label('Danger zone')
->dropdownPlacement('right-start')
->dropdownWidth('sm'),
])
->label('More actions')
->icon('ellipsis-horizontal');
ActionGroup::make('review', [
BulkAction::make('approve')->color('primary'),
BulkAction::make('reject')->color('danger'),
ActionGroup::make('more', [
BulkAction::make('defer'),
BulkAction::make('assign'),
])->label('More'),
])
->label('Review selected')
->buttonGroup();
BulkAction::make('publish')
->chunkBy(250)
->action(fn (Collection $records) => Post::whereKey($records->modelKeys())->update(['published' => true]));
BulkAction::make('export')
->chunkBy(500)
->queueUsing(ExportUsers::class, queue: 'exports');
final class ExportUsers implements ShouldQueue
{
public function __construct(public array $keys, public array $data) {}
}
BulkAction::make('export')
->authorizeUsing(fn (Request $request): bool => $request->user() !== null)
->authorizeIndividualRecords(fn (User $record): bool => $record->status !== 'suspended')
->action(function (BulkAction $action, Collection $records): int {
$blocked = $records->filter(fn (User $record): bool => $record->role === 'viewer');
$blocked->each(fn (User $record) => $action->reportRecordFailure($record, 'Viewers cannot be exported.'));
return $records->count() - $blocked->count();
})
->successNotificationTitle('Export queued.')
->failureNotificationTitle('Some users were left out of the export.');
BulkAction::make('export')
->modal(
ActionModal::make(fn (Collection $records): string => "Export {$records->count()} users?")
->description(fn (Collection $records): string => 'Starting with '.$records->first()->name.'.')
->submitLabel('Export'),
)
->authorizeUsing(fn (Request $request): bool => $request->user() !== null)
->action(fn (Collection $records): int => $records->count());
use App\Models\User;
use Inlay\Actions\Action;
use Inlay\Forms\Fields\TextInput;
Action::make('suspend')
->form(fn (User $record): array => [
TextInput::make('reason')
->rd, array $data): array => [
...$data,
'reason' => trim((string) ($data['reason'] ?? '')),
])
->afterFormFilled(fn (array $data) => audit('suspend.form-mounted', $data))
->authorizeUsing(fn (User $record): bool => auth()->user()?->can('suspend', $record) === true)
->action(function (User $record, array $data): void {
$record->update([
'status' => 'suspended',
'suspension_reason' => $data['reason'],
]);
});
Action::make('publish')
->icon('check')
->iconPosition('after')
->size('large')
->tooltip('Publishes immediately')
->badge(3)
->outlined()
->disabled(fn (): bool => $post->isPublished());
bash
vendor/bin/pest tests/ActionTest.php