Skip to content

[BUG] Errors when using with media-library #122

Description

@henriquecm

What happened?

There are 2 problems when trying to generate types while using spatie/media-library

  1. Error in the ModelInspector while trying to invoke the relationships, media-library has a couple of methods related to temporary upload that are paid features and aren't available in the free version, and they throw an exception when you try to use them, and this causes the whole process to end prematurely.
    To work around this at first I decided to just not include the Media model, typed it manually and import in the models.d.ts, but this is where the second problem appeared.

  2. The relationship generated has the wrong name, the model name is "Media", but the relationships always use "Medium", which is probably trying to make a singular form of the word media.

After some time, I decided to extend the "Media" model for other reason, but I could take advantage of this to override the methods throwing exceptions, this solved the first problem, but not the second one.

The relationship itself it morphMany, but my main use is to make them into attributes when they are single file collections to make the usage easier.

Funny enough, using "included_models", will generate the model without errors, but additional_paths throws the exception like I mentioned before.

Expected Behavior

  1. Handle exceptions thrown in the Model Inspector to not halt the command execution.
  2. Not modify the Model name in the relationship.

Steps To Reproduce

  1. Install Media Library in the project.
  2. Setup a model to use it.
  3. Add the Media model directory to "additional_paths". ./vendor/spatie/laravel-medialibrary/src/MediaCollections/Models
  4. Run php artisan model:typer

Metadata

Metadata

Assignees

No one assigned

    Labels

    StalebugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions