modeltyper icon indicating copy to clipboard operation
modeltyper copied to clipboard

Feature Request: optionally type vendor models

Open robverhoef opened this issue 8 months ago • 11 comments

A model may use vendor provided models. Or sometimes you just need those models in the front end. I currently don't see an easy way of generating interfaces for these models.
Automagically following related (vendor-) models might become messy quickly. I get that.
But even the option to manually point to specific vendor models, for instance: ./vendor/spatie/laravel-permission/src/Models/Permission.php could also be a great time saver.

robverhoef avatar Jun 12 '25 12:06 robverhoef

PR's are more than welcome!

acidjazz avatar Jun 12 '25 18:06 acidjazz

@robverhoef How does the output look for a vendor model like that using the internal Laravel model:show command?

tcampbPPU avatar Jun 12 '25 20:06 tcampbPPU

@robverhoef How does the output look for a vendor model like that using the internal Laravel model:show command?

It will look like this:

php artisan model:show "Spatie\Permission\Models\Permission"

Output:

  Spatie\Permission\Models\Permission .......................................
  Database ........................................................... sqlite
  Table ......................................................... permissions

  Attributes .................................................... type / cast
  id increments, unique ....................................... integer / int
  name fillable ..................................................... varchar
  guard_name fillable ............................................... varchar
  created_at nullable, fillable ......................... datetime / datetime
  updated_at nullable, fillable ......................... datetime / datetime

  Relations .................................................................
  roles BelongsToMany ......................... Spatie\Permission\Models\Role
  users MorphToMany ......................................... App\Models\User
  permissions MorphToMany ............... Spatie\Permission\Models\Permission

  Events ....................................................................

  Observers .................................................................
  deleting ................................................. Closure, Closure
  saved ............................................................. Closure
  deleted ........................................................... Closure

robverhoef avatar Jun 13 '25 09:06 robverhoef

it's because we use laravels app directive i'm not sure i want to avoid using that but maybe a flag to allow full (slow) search of models to pick all them in the vendor directory up. or perhaps a way to add the known vendor models into the config and we can read and map from there

tcampbPPU avatar Jul 09 '25 20:07 tcampbPPU

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Aug 09 '25 02:08 github-actions[bot]

I think the best solution would be to add a config options to include som files. Today we have included_models in the config, but there are lots of scenarios where you want to add a file - without removing those included by default.

#60 Could be solved by this #87 As well

My proposed solution is to add an option which forces some models & enums to be parsed. At first glance, the included_models is a confusion config option as well. A more proper name would be only_models, then included_models could be those that are "forced". However, changing this would be a breaking change so maybe just come up with another config name in that case.

Livijn avatar Aug 31 '25 08:08 Livijn

Hey, I think we could use composers autoloader directly instead of relying on laravels proxy to it. Something like this? https://github.com/fumeapp/modeltyper/compare/master...RyanSchaefer:modeltyper:master

This is just a PoC (I don't know if this would slow things down and how exactly is best to incorporate this into the config) but it seems to work. Might be more reliable than the name generation previously used.

RyanSchaefer avatar Sep 24 '25 03:09 RyanSchaefer

@RyanSchaefer thanks for the suggestion and poc! i didn't know about that util, its something i can look into.

tcampbPPU avatar Sep 24 '25 13:09 tcampbPPU

@tcampbPPU Going to take a crack at formalizing this tonight.

Any advice for what could potentially be replaced?

Is that change touching too much of core functionality?

Would an "additional_paths" config variables make sense here?

RyanSchaefer avatar Sep 26 '25 19:09 RyanSchaefer

@tcampbPPU Going to take a crack at formalizing this tonight.

Any advice for what could potentially be replaced?

Is that change touching too much of core functionality?

Would an "additional_paths" config variables make sense here?

I like the idea of a "additional_paths" config variable.

For what to change it should just pretty much be the GetModels action, this part:

collect(File::allFiles(app_path()))

thats where a config or additional path config would work for when there are cases outside of the traditional scope to locate models

tcampbPPU avatar Sep 30 '25 14:09 tcampbPPU

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Oct 31 '25 02:10 github-actions[bot]