Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single Image option and collections #439

Open
matthewjumpsoffbuildings opened this issue Apr 8, 2024 · 1 comment
Open

Single Image option and collections #439

matthewjumpsoffbuildings opened this issue Apr 8, 2024 · 1 comment

Comments

@matthewjumpsoffbuildings

I am finding the 'collection' approach to single image handling strange.

If I have a model with multiple image fields, and I want them to all only allow a single image per field, I have to make a bunch of different collections? This makes no sense to me, since I want all the image fields to draw from the same collection, but not to allow each individual field to select more than one item from the collection in question, and definitely not to delete all other items in the collection on the base media table.

This 'single' option should be set at the Field level, not implemented at the underlying spatie media collection level?

Am I just misunderstanding the docs, or is creating a bunch of separate collections the only way make a model have multiple single selection only image fields?

@Flavien-Panunzio
Copy link

Flavien-Panunzio commented Dec 4, 2024

I just found the solution to the problem I encountered too. In reality, it is not specified but you simply have to define the collection as "singleFile" in the Model corresponding to the name of the Nova form fields. It is not clearly specified in the doc, so here is my example :

``
// Model
public function registerMediaCollections(): void {
$this->addMediaCollection('singleFile')->singleFile();
$this->addMediaCollection('multipleFile');
}

//Nova ressource
Images::make('Single File', 'singleFile'),

Images::make('Multiple Files', 'multipleFile'),
``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants