Files
einundzwanzig-portal/app/Nova/Participant.php
2023-02-19 18:05:16 +01:00

96 lines
2.0 KiB
PHP

<?php
namespace App\Nova;
use App\Notifications\ModelCreatedNotification;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
class Participant extends Resource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = \App\Models\Participant::class;
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
'id',
'first_name',
'last_name',
];
public function title()
{
return $this->first_name.' '.$this->last_name;
}
public static function afterCreate(NovaRequest $request, Model $model)
{
\App\Models\User::find(1)
->notify(new ModelCreatedNotification($model, str($request->getRequestUri())
->after('/nova-api/')
->before('?')
->toString()));
}
/**
* Get the fields displayed by the resource.
*/
public function fields(Request $request): array
{
return [
ID::make()
->sortable(),
Text::make('First name')
->rules('required', 'string'),
Text::make('Last name')
->rules('required', 'string'),
];
}
/**
* Get the cards available for the request.
*/
public function cards(Request $request): array
{
return [];
}
/**
* Get the filters available for the resource.
*/
public function filters(Request $request): array
{
return [];
}
/**
* Get the lenses available for the resource.
*/
public function lenses(Request $request): array
{
return [];
}
/**
* Get the actions available for the resource.
*/
public function actions(Request $request): array
{
return [];
}
}