Laravel Artisan General Command: The tinker Command

December 7, 2016 —John Koster

The tinker command can be used to start an interactive language shell for interacting with your Laravel framework application. The tinker command defines an optional array input include. Traditionally this is used to include auto-loaders for various libraries or configuration values. These files are included before the interactive shell has completely loaded.

The following example demonstrates the basic usage of the tinker command:

1php artisan tinker

The interaction language shell is ready when output similar to the following appears:

1Psy Shell v0.7.2 (PHP cli) by Justin Hileman

To exit the interactive shell, issue the exit command:

1# Exit the interactive language shell.

The shell will output Exit: Goodbye and return to the terminal.

#Loading External Files Into the Interactive Shell

To load external files into the interactive shell, supply them as arguments to the tinker command (they will be passed to the command's include input). The include parameter is defined as an array so it allows for multiple files to be loaded.

The following example demonstrates how to load files using the tinker command:

1# Replace <file> with the path to the file to include.
2php artisan tinker <file>

Assuming we had the following file named test.php located in the same directory as artisan:

3echo "Hello, from the test.php file.\n";

We could load it using tinker like so:

1# Load the test.php file with tinker.
2php artisan tinker test.php

The output would be similar to the following:

1Psy Shell v0.7.2 (PHP cli) by Justin Hileman
2Hello, from the test.php file.

Some absolutely amazing

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.