GithubHelp home page GithubHelp logo

Comments (5)

toonvandenbos avatar toonvandenbos commented on May 28, 2024 1

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.

OliverZiegler avatar OliverZiegler commented on May 28, 2024 1

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.

GarethSomers avatar GarethSomers commented on May 28, 2024 1

Hey guys,

When running:

Pressing save won't do anything 😕

Update

My fault, ignore me :)

from nova-page.

amidesfahani avatar amidesfahani commented on May 28, 2024 1

does it world?

from nova-page.

toonvandenbos avatar toonvandenbos commented on May 28, 2024

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):

  1. Switch Nova-Page's "default_source" configuration to Database ;
  2. 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;
}
  1. Go back to nova-page's configuration and set sources.database.model to your new Page model (or whatever you named it).

from nova-page.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.