Samuel Oloruntoba has written a good tutorial about using Tinker to mess around with data in our Laravel apps.


Today we'll talk about how to use one of Laravel's lesser-known features to quickly read data from our Laravel applications. We can use Laravel artisan's built-in php artisan tinker to mess around with your application and things in the database.

Laravel artisan's tinker is a repl (read-eval-print loop). A repl translates to read-eval-print-loop, and it is an interactive language shell. It takes in a single user input, evaluates it, and returns the result to the user.

A quick and easy way to see the data in your database.

Wouldn't it be nice to see the immediate output of commands like:

// see the count of all users

// find a specific user and see their attributes
App\User::where('username', 'samuel')->first();

// find the relationships of a user
$user = App\User::with('posts')->first();

With php artisan tinker, we can do the above pretty quickly. Tinker is Laravel's own repl, based on PsySH. It allows us to interact with our applications and stop dd()ing and die()ing all the time. A lot of us know the insanity that ensues when there are print_r()s and dd()s all over our code.