Came across this on Twitter today on how to execute quickly with Laravel Tinker. Seemed like a handy script!
Laravel productivity tip! Add this little function to your bash profile to quickly execute anything with the Tinker command and get the results instantly. pic.twitter.com/qIB9pQCTWt
— Philo Hermans (@philo01 ) October 16, 2021
Here's the gist of it that you should add to your bash profile
function tinker()
{
if [-z "$1"]
then
php artisan tinker
else
php artisan tinker --execute="dd($1);"
fi
}
Then on your terminal, you can execute it with the shortcut, instead of php artisan tinker
and directly as tinker 'User::first()'
The author of the tweet also provided this as an explanation:
When you enter “tinker” it will execute the bash function. If no arguments are given, it will simply run “php artisan tinker”. If you provide any argument, this argument is forwarded as the “execute” parameter for the tinker command. The “dd” fn will prettify the output.
Top comments (0)