Execute quickly with Laravel Tinker
1 min read

Execute quickly with Laravel Tinker

Shortcut for Laravel Tinker on using it efficiently

Came across this on Twitter today on how to execute quickly with Laravel Tinker. Seemed like a handy script!

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.