laravel / tinker

Powerful REPL for the Laravel framework.
https://laravel.com/docs/artisan#tinker
MIT License
7.32k stars 130 forks source link

Alias only models #126

Closed SebastianSchoeps closed 3 years ago

SebastianSchoeps commented 3 years ago

I often have projects where e.g. a Livewire component "User" is aliased before the model with the same name. That means that I have to type the namespace for the user model or enter every model manually in the config. I basically only ever need models aliased. Would a PR with something like the following in ClassAliasAutoloader be accepted?

if(config('tinker.only_models') 
    && !(new \ReflectionClass($class))->isSubclassOf(\Illuminate\Database\Eloquent\Model::class)) {
    return false;
}

Tinker startup time will go up a little, but a) this time will be saved as soon as I have to enter the first model namespace b) it's only optional and disabled by default

Thanks!

driesvints commented 3 years ago

We already have config options to not alias classes you want to ignore like the Livewire components you mention: https://github.com/laravel/tinker/blob/2.x/config/tinker.php#L46

SebastianSchoeps commented 3 years ago

@driesvints Thanks. Yes, I know about that, but that means, that I would have to constantly add new classes there. But if that's the way to go, so be it.