orchidsoftware / crud

Simplify the process of building CRUD (Create, Read, Update, Delete) functionality in Laravel using the features of Orchid.
https://orchid.software
MIT License
136 stars 34 forks source link

Incorrect error 'The model "App\Models\X" must have the required orchid/platform traits.' #89

Open vilocity-brian opened 1 year ago

vilocity-brian commented 1 year ago

Because of the way Orchid\Crud\Arbitrator checks if the model implements the required traits (Filterable), it only finds the trait if the model directly uses it... but not if the model extends a model that has use Filterable;

Three solutions come to mind:

  1. Write a new function like the trait_uses_recursive helper function that also traverse the parent classes.
  2. Stop validating the traits and rely on the developers to understand the Call to undefined method Illuminate\Database\Eloquent\Builder::filters() error they'll get.
  3. Improve the error to state that the trait must be included directly on the Model being used as a resources.

I'm mostly raising this issue so that if someone else runs into the error, they don't spin their wheels for 5 hours like I did. If nothing changes, at least this issue report may come up in their search.

In the meantime, I suggest at least a documentation update. https://github.com/orchidsoftware/orchid.software/commit/8aded3540441a9c1eff28c1a8d7a5c5af788985e

parse-code commented 4 months ago

@vilocity-brian you saved my day, bro