Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

spycrabo's avatar

Passing command to tinker from bash

I want to write simple script which should use tinker and pass something to tinker. For example, I want to execute Model::someScope()->count(). When doing it without separate bash script I would write:

$ php artisan tinker
>>> Model::someScope()->count()
=> 1000
>>> 

But I want to do the same but in the bash script:

# script.sh
code="Model::scopeScope()->count()"

php artisan tinker

# Here must be passing code to tinker

How can I achieve calling my code in tinker using bash script?

0 likes
2 replies
CorvS's avatar

@spycrabo Tinker provides a "execute" parameter you can use:

php artisan tinker --execute="Model::scopeScope()->count()"
spycrabo's avatar

Thanks! Found this option in my laravel 8 project. But I dont get actual output (expecting int return of count() method) to the shell. I only got output like this:

[!] Aliasing 'Model' to 'App\Models\Model' for this Tinker session.

Please or to participate in this conversation.