|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Nova; |
| 4 | + |
| 5 | +use Illuminate\Http\Request; |
| 6 | +use Laravel\Nova\Fields\Boolean; |
| 7 | +use Laravel\Nova\Fields\ID; |
| 8 | +use Laravel\Nova\Fields\Number; |
| 9 | +use Laravel\Nova\Fields\Text; |
| 10 | +use Laravel\Nova\Fields\Textarea; |
| 11 | +use Laravel\Nova\Http\Requests\NovaRequest; |
| 12 | + |
| 13 | +class DreamJobRoleModel extends Resource |
| 14 | +{ |
| 15 | + public static $group = 'Content'; |
| 16 | + |
| 17 | + public static $model = \App\DreamJobRoleModel::class; |
| 18 | + |
| 19 | + public static $title = 'slug'; |
| 20 | + |
| 21 | + public static $search = [ |
| 22 | + 'first_name', |
| 23 | + 'last_name', |
| 24 | + 'slug', |
| 25 | + 'role', |
| 26 | + ]; |
| 27 | + |
| 28 | + public static function label() |
| 29 | + { |
| 30 | + return 'Dream Jobs Role Models'; |
| 31 | + } |
| 32 | + |
| 33 | + public static function singularLabel() |
| 34 | + { |
| 35 | + return 'Dream Jobs Role Model'; |
| 36 | + } |
| 37 | + |
| 38 | + public function fields(Request $request): array |
| 39 | + { |
| 40 | + return [ |
| 41 | + ID::make()->sortable(), |
| 42 | + |
| 43 | + Text::make('First Name', 'first_name')->rules('required', 'max:255'), |
| 44 | + Text::make('Last Name', 'last_name')->rules('required', 'max:255'), |
| 45 | + Text::make('Slug', 'slug') |
| 46 | + ->rules('required', 'max:255', 'unique:dream_job_role_models,slug,{{resourceId}}') |
| 47 | + ->help('Used in URL, e.g. anny-tubbs'), |
| 48 | + Textarea::make('Role', 'role')->rules('required'), |
| 49 | + |
| 50 | + Text::make('Image URL', 'image') |
| 51 | + ->rules('required', 'max:2048') |
| 52 | + ->help('Path from site root, e.g. /images/dream-jobs/anny-tubbs.png'), |
| 53 | + Text::make('Country Code', 'country') |
| 54 | + ->rules('required', 'max:8') |
| 55 | + ->help('Flag code used by existing assets, e.g. be, fr, gr'), |
| 56 | + |
| 57 | + Textarea::make('Description 1', 'description1')->nullable(), |
| 58 | + Textarea::make('Description 2', 'description2')->nullable(), |
| 59 | + |
| 60 | + Text::make('Profile Link', 'link')->nullable()->rules('nullable', 'max:2048'), |
| 61 | + Text::make('Video Embed URL', 'video')->nullable()->rules('nullable', 'max:2048'), |
| 62 | + Text::make('Pathway Map Filename', 'pathway_map_link') |
| 63 | + ->nullable() |
| 64 | + ->rules('nullable', 'max:255') |
| 65 | + ->help('Filename in /public/docs/dream-jobs/, e.g. Career Pathway Map Anny Tubbs.pdf'), |
| 66 | + |
| 67 | + Number::make('Position', 'position') |
| 68 | + ->min(0) |
| 69 | + ->default(0) |
| 70 | + ->help('Lower numbers appear first.'), |
| 71 | + |
| 72 | + Boolean::make('Active', 'active')->default(true), |
| 73 | + ]; |
| 74 | + } |
| 75 | + |
| 76 | + public static function indexQuery(NovaRequest $request, $query) |
| 77 | + { |
| 78 | + return $query->orderBy('position')->orderBy('first_name'); |
| 79 | + } |
| 80 | +} |
0 commit comments