Laravel Artisan Tinker: The history Command

December 7, 2016 —John Koster

The history command can be used to retrieve information about the commands have been previously entered in the Tinker REPL session. By using its various options, you can quickly search and find any history item, replay it and even save it to a file.

The following example session demonstrates how to use the history command to repeat an expression:

1>>> $user = new App\User;
2=> App\User {#645}
3>>> history --head 1 --replay
4Replaying 1 line of history
5--> $user = new App\User;
6=> App\User {#648}
7>>>

Issuing just the history command would allow us to view the recently entered commands:

1>>> history
20: $user = new App\User;
31: history --head 1 --replay
42: $user = new App\User;
53: history

Like the ls command, the history command provides many options to help narrow the search space as well as export options. Issue the ? history command within a Tinker REPL session to learn more about the history command options.

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.