1. Go to this page and download the library: Download sietse85/nova-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/ */
sietse85 / nova-button example snippets
use Sietse85\NovaButton\Button;
public function fields(Request $request)
{
return [
ID::make('ID', 'id')->sortable(),
Text::make('Name', 'name'),
Button::make('Notify'),
];
}
Button::make('Cancel Account')->confirm('Are you sure?'),
Button::make('Cancel Account')->confirm('Confirmation', 'Are you sure you want to cancel your account?'),
Button::make('Cancel Account')->confirm('Confirmation', 'Are you sure you want to cancel your account?', 'Cancel'),
// One class
Button::make('Notify')->classes(['some-class'])
// Or multiple classes
Button::make('Notify')->classes(['some-class', 'another-class'])
// One class
Button::make('Notify')->confirm('sure?')->modalClasses(['some-class'])
// Or multiple classes
Button::make('Notify')->confirm('sure?')->modalClasses(['some-class', 'another-class'])
Button::make('Delete')->style('danger')
namespace App\Nova\Lenses;
class UsersWithoutConfirmation extends Lens
{
public static function query(LensRequest $request, $query)
{
return $query
->select(['users.id', 'users.name'])
->whereNull('email_verified_at');
}
public function fields(Request $request)
{
return [
ID::make('ID', 'id'),
Text::make('Name', 'name'),
Button::make('Mark As Confirmed'),
];
}
}
namespace App\Listeners;
use Sietse85\NovaButton\Events\ButtonClick;
class ConfirmUser
{
public function handle(ButtonClick $event)
{
if ($event->key == 'mark-as-confirmed') {
$event->resource->email_verified_at = now();
$event->resource->save();
}
}
}