Can I run a command in Laravel Tinker within just one entry in the CLI?

5.9k views Asked by At

I want to start using tinker to debug functions much faster. The issue is that for every change I need to stop and start tinker again.

I'm hoping I can use something like you have with mysql; you can start mysql and do your queries like that, but you can also run something like this mysql -u root -e "select * from users" which just works without starting up the mysql interface.

So I'm trying to find a way to do something like this

> tinker -e "User::find(1)->email"
"[email protected]"
>
1

There are 1 answers

1
viryl15 On BEST ANSWER

You can use: php artisan tinker --execute="dump(User::find(1)->email)" which you can write a little bit shorter to be php artisan tinker --execute="dd(User::find(1)->email)".

If you want to see more options, execute this: php artisan tinker -h. As you can see there, unfortunately there is no abbreviation for the --execute[=EXECUTE] flag.