I am installing this Nova package: https://novapackages.com/packages/classic-o/nova-media-library and am having trouble figuring out where to put this block of code:
Add field to the resource:
use ClassicO\NovaMediaLibrary\MediaLibrary;
class Post extends Resource
{
...
public function fields(Request $request)
{
return [
...
MediaLibrary::make('Image'),
...
];
}
...
}
I've looked around, but am very new to Laravel, so I'm just a little confused. I understand that it is a field, so I've looked here: https://nova.laravel.com/docs/1.0/resources/fields.html#place-field, but don't really understand the location where these can be registered.
I appreciate any insight or context here. Thank you!
With Laravel Nova, they tried to make everything as easy as possible. So, a Resource
is what adds all the functionality to your Model
, and a Model
represents (in some way) a table in your database. A resource is just a class that extends from Resource
, and has some functions to be completely functional.
So, in your example, you should have a Model
called Post
, the code showing is an incomplete Resource
called Post
(that's why you se those three points before and after the function). As you read the Resource
documentation, you will see that the function fields()
always returns an array of Fields
. The code
MediaLibrary::make('Image')
is, indeed, a field, that's why it's inside de array. The code that you have is just an example, and it's purpose is to illustrate that the MediaLibrary
field can be used as any other field. I strongly recommend that you take enough time to read about Models, Eloquent, Resources and Fields.