Comments (5)
Hi @OliverZiegler,
The problem here is that Spatie's library requires a model in order to link the media to it. By default, this package does not use models (data is stored in JSON files). Therefore, you should switch to database storage. This will however probably not work with the current version of nova-flexible-content, since the model is difficult to fetch from inside a Flexible content.
I'm working on a fix for a similar issue (the one you linked in your post) as we speak, I'll try to find a solution that also fixes this one.
from nova-page.
Thanks for the fast response!!
So with the still missing PR from advanced-nova-media-library I got it working with nova-flexible-content but with some limitations...
- Adding the same Layout multiple times overwrites the images (related to this issue I think.)
- Defining single file collections won't work (also related to this issue
One more issue (not related to nova-flexible-content) is adding Images to the page directly.
Defining advanced-nova-medialibrary fields on the Template worked for me (inspired by your trait in nova-flexible-content) by adding the following code to the template:
Make the template implement use Spatie\MediaLibrary\HasMedia\HasMedia;
and adding the trait with use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
.
Furthermore adding:
protected function getMediaModel() : HasMedia
{
$model = $this->getSource()->getOriginal($this);
\Log::info($model);
if(is_null($model) || !($model instanceof HasMedia)) {
throw new \Exception('Origin HasMedia model not found.');
}
return $model;
}
public function getMedia(string $collectionName = 'default', $filters = [])
{
return app(MediaRepository::class)->getCollection($this->getMediaModel(), $collectionName, $filters);
}
public function addMedia($file)
{
return app(FileAdderFactory::class)
->create($this->getMediaModel(), $file)
->preservingOriginal();
}
from nova-page.
Hey guys,
When running:
whitecube/nova-page:dev-master
whitecube/nova-flexible-content@cfd8719https://github.com/whitecube/nova-flexible-content/pull/71
Pressing save won't do anything 😕
Update
My fault, ignore me :)
from nova-page.
does it world?
from nova-page.
Hi @OliverZiegler,
Could you update both packages (using dev-master
for nova-page) and tell me if this issue is fixed?
Here's how I got it working (you should probably re-publish the package's configuration file):
- Switch Nova-Page's "default_source" configuration to Database ;
- Create a new model like this:
namespace App;
use Whitecube\NovaPage\Sources\StaticPage;
use Spatie\MediaLibrary\HasMedia\HasMedia;
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
class Page extends StaticPage implements HasMedia
{
use HasMediaTrait;
}
- Go back to nova-page's configuration and set
sources.database.model
to your newPage
model (or whatever you named it).
from nova-page.
Related Issues (20)
- Class "Route" not found
- Class "App" Not Found
- Method App\\Nova\\Templates\\Formations::forceFill does not exist HOT 4
- Title will not save in templates HOT 5
- Argument 1 passed to StaticResource HOT 3
- Deleting Images in Flexible Content Field HOT 1
- PHP 8 error "Required parameter $closure follows optional parameter $date" HOT 2
- Page Resource Search does not work
- FR: Hide options from sidebar HOT 2
- Ability to hide nova-option HOT 1
- Detail view broken HOT 7
- Cast Date Field HOT 3
- PHP 8 Compatibility? -- Required parameter follows optional parameter HOT 2
- Remove template declaration in routes HOT 3
- Arabic encoding
- Nova 4 Support HOT 6
- TypeError: Cannot read properties of undefined (reading 'resource') HOT 3
- Error deleting a file HOT 1
- Call to undefined method Whitecube\NovaPage\Pages\Query::exists() HOT 3
- Can this be used for multiple page layouts? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nova-page.