Package Data | |
---|---|
Maintainer Username: | tpraxl |
Maintainer Contact: | thomas@macrominds.de (Thomas Praxl) |
Package Create Date: | 2016-10-14 |
Package Last Update: | 2017-04-19 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-07 03:12:35 |
Package Statistics | |
---|---|
Total Downloads: | 40 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 5 |
Total Watchers: | 2 |
Total Forks: | 2 |
Total Open Issues: | 0 |
If you have an action that needs to be confirmed before proceeding, or you want to let the user choose from multiple options, then this solution might just be exactly what you are looking for.
The user has chosen to delete a person. That means that all upcoming events, hosted by this person, need to be canceled. But you don't want to cancel them silently. You want to be polite and ask the user first:
Simply return the Choice where you would normally return the redirect()
in your Controller.
return Choice::make(
'Deleting the person will cancel some events',
sprintf(
'%s events are going to be canceled if you delete %s',
$numEvents, $personName
),
[
Option::makeCancel('Cancel deletion'),
Option::make(
'Delete person and cancel events',
route('customer.force-destroy', ['person' => $person]),
'DELETE',
[],
true),
]
);
Depending on the choice of the user, she will be redirected either
back to the previous page (standard Option::makeCancel
behaviour) or
to any route of your liking. You are not limited to two options.
composer require macrominds/laravel-choice
.
You should call php artisan vendor:publish --tag=laravel-choice
.
This will add the customizable views to resources/views/vendor/choice/*
and the minimalistic
styling resources/assets/sass/vendor/choice/_choice.scss
to your project.
You should @import "vendor/choice/choice";
in your app.scss
afterwards.
In your master blade view, below all visible page elements, just before the end of your
</body>
or just before the <script>
s at the bottom, add the following line:
{{ macrominds\laravel\choice\Choice::render() }}
Next? Nothing. You are ready to go. Just replace a return redirect()
statement
in your Controller with return Choice::make (//...
.