Skip to content

Commit

Permalink
Update image & video resources in nova #1 #2
Browse files Browse the repository at this point in the history
  • Loading branch information
drewroberts committed Dec 21, 2020
1 parent 27678dd commit c752243
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/Models/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ protected static function boot()
$video->creator_id = auth()->id();
}
});

static::saving(function ($video) {
if (empty($video->identifier)) {
throw new \Exception('Video must have an identifier on YouTube or Vimeo.');
}
if (empty($video->source)) {
$video->source = 'youtube';
}
});
}

public function image()
Expand Down
14 changes: 11 additions & 3 deletions src/Nova/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function fieldsForIndex(NovaRequest $request)
{
return [
ID::make()->sortable(),
CloudinaryImage::make('Image', 'filename'),
Text::make('Filename')->sortable(),
Text::make('Width')->sortable(),
Text::make('Height')->sortable(),
Expand All @@ -44,16 +45,23 @@ public function fields(Request $request)
})->hideWhenUpdating(),
Text::make('Width')->exceptOnForms(),
Text::make('Height')->exceptOnForms(),
Text::make('Description')->sortable(),
Text::make('Alt')->sortable(),
Text::make('Credit')->sortable(),

new Panel('Info Fields', $this->infoFields()),
new Panel('Data Fields', $this->dataFields()),

HasMany::make('Videos'),
];
}

protected function infoFields()
{
return [
Text::make('Description')->nullable(),
Text::make('Alt')->nullable(),
Text::make('Credit')->nullable(),
];
}

protected function dataFields()
{
return [
Expand Down
26 changes: 20 additions & 6 deletions src/Nova/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Panel;
Expand Down Expand Up @@ -36,18 +37,31 @@ public function fieldsForIndex(NovaRequest $request)
public function fields(Request $request)
{
return [
ID::make(),
Text::make('Name'),
Text::make('Source'),
Text::make('Title'),
Text::make('Discription'),
BelongsTo::make('Image'),
Text::make('Identifier')->required()->help(
'The ID from YouTube or Vimeo'
),
Text::make('Name')->required(),

new Panel('Info Fields', $this->infoFields()),
new Panel('Data Fields', $this->dataFields()),

];
}

protected function infoFields()
{
return [
Select::make('Source')->options([
'youtube' => 'YouTube',
'vimeo' => 'Vimeo',
'other' => 'Other',
])->withMeta(['value' => $this->source ?? 'youtube'])->required()->displayUsingLabels(),
Text::make('Title')->nullable(),
Text::make('Description')->nullable(),
BelongsTo::make('Image')->nullable()->showCreateRelationButton(),
];
}

protected function dataFields()
{
return [
Expand Down

0 comments on commit c752243

Please sign in to comment.