Laravel's Tinker REPL is useful for conveniently experimenting with models, however it does not seem possible to import a namespace, requiring the model namespace to be laboriously typed. For instance, this works:
$ php artisan tinker
[1] $list = new mysweetapp\Todolist;
[2] > echo get_class($list);
mysweetapp\Todolist
This does not:
$ php artisan tinker
[1] use mysweetapp\Todolist;
// false
[2] $list = new Todolist;
[3] echo get_class($list);
Boris\EvalWorker
Is there some way to import namespaces into Tinker or is it just not yet supported? Mind you I definitely want to use namespaces, I just don't want to repeatedly type in the namespace. :-)
Look at this https://softonsofa.com/tinker-like-a-boss-in-psysh/
You can't do this with use namespace in the repl itself, but here's what you may do:
// config/local/app.php
'aliases' => append_config([
'Todolist' => 'Mysweetapp\Todolist',
... // more
]),
Then in your local env you will be able to access your models without typing namespace, and if you're not in local env, then run tinker forcing it:
php artisan tinker --env=local
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With