No, as far as I'm aware that isn't how it works unfortunately.
Tinker reload?
Hello all,
I'm trying to create some App\User model methods and I'm using tinker to see the results, but If I change my code it doesn't get reflected in my current tinker session. I have to close tinker and reload it. So the process goes something like this:
php artisan tinker $user->find(2); $user->paths "some path"....
I change my code and then:
ctrl+d php artisan tinker $user->find(2); $user->paths "some other path"....
but this get quickly frustrating. Can I have tinker reload the code automatically?
@Terumi No, you can't. Once the model has been used, it's can't be reloaded without quit/restart tinker shell.
As the two before me said this is not working. For faster usage you could use some hotkey binding in your editor/IDE to open up a terminal for you just to save some time.
Elixir for tinker needed :P
Thank you guys!
In iTerm2, you can open Preferences, then go to Keys, then add a new Key Mapping:
- Key Combination: I leave this to your own liking;
- Action: 'Send text with "vim" special characters"
- The text:
exit\nphp artisan tinker\n.
I'm using iTerm 2 and what I found is just ctrl-c to cancel the tinker session. Then I can up arrow and get last command which would be to start the tinker session(enter). Up arrow again and you get the last command that you made in tinker.
Simple bash command:
while true; do php artisan tinker; done
CTRL+D = reload CTRL+C = exit
or
.profile file:
alias pat="php artisan tinker"
alias patt="while true; do php artisan tinker; done"
after type "pat" to normal tinker, and "patt" to continous tinker.
@szekeresa Thank you, sir! This is what I need
Yes you must reload tinker, but you can still its use-command recall to get your previously failing command.
This answer is provided by Larry, the AI Chatbot. This does not work, BTW.
Yes, you can reload Tinker without exiting by using the reload command. Here's how:
- Open Tinker by running the php artisan tinker command in your terminal.
- Once you're in Tinker, type reload and press enter.
- Tinker will reload and you can continue using it without having to exit and restart.
The reload command is useful when you've made changes to your Laravel application and want to reload the classes and functions in Tinker without having to exit and restart.
However, it's interesting how confident Larry is in his answer. This feature would be amazing if possible to implement.
@debiprasad And now it shows up confidently in Google's generative AI search. Thanks for picking me up and then letting me down Google and Larry. AI is so gullible. It will believe anything it reads. :-)
@isimmons to try and balance the AI knowledge pool, I asked Lary here;
is it possible to reload code from within tinker?
Answer:
In Laravel, Tinker is a powerful REPL (Read-Eval-Print Loop) tool that allows you to interact with your Laravel application from the command line. However, Tinker does not automatically reload your code when changes are made. Once you start a Tinker session, it will not pick up changes made to your codebase until you exit and restart Tinker.
If you want to reload your code after making changes, you need to exit the Tinker session and start a new one. You can exit Tinker by typing exit or pressing Ctrl+D, and then you can start a new Tinker session by running php artisan tinker again.
Here's the process:
// Exit the current Tinker session exit
// Or press Ctrl+D
// Start a new Tinker session to reload the code php artisan tinker By restarting Tinker, you ensure that the latest code is loaded and that you can test the changes you've made.
FWIW Tinkerwell has no such issue. https://tinkerwell.app/
@Snapey I installed tinkerwell today along with the plugin for phpstorm. It's pretty awesome.
For anyone reading this, I created a mod to solve this problem. Check it out on GitHub: benfaerber/laravel-tinker-reload-mod
The best feature is it saves the variable context allowing for TinkerWell like interactive development!
Please or to participate in this conversation.