Level 27
@spycrabo Tinker provides a "execute" parameter you can use:
php artisan tinker --execute="Model::scopeScope()->count()"
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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?
Please or to participate in this conversation.