Home · Projects · Templates · Articles · Speaking · Uses · Contact · FAQ · Community · AI Tools · Developer Tools · Items

Laravel Tinker Tutorial: Test Your Code in the Terminal

Learn how to use Laravel Tinker to interact with your database,test Eloquent queries, and debug application logic directly from your terminal. Boost efficiency.

Tinker is an interactive shell that loads your entire Laravel application. You can run PHP and Eloquent code line by line and see results instantly, with no routes, controllers, or views required. Starting Tinker php artisan tinker You'll see a prompt like > . Type PHP, press Enter, and Tinker prints the result. Basic Examples > 2 + 2 = 4 > now() = Illuminate\Support\Carbon @1767225600 {...} > Str::slug('Hello Laravel World') = "hello laravel world" Querying Your Database > App\Models\User::count() > App\Models\User::first() > App\Models\Product::where('price', '>', 100) >get() Tip: to avoid typing the full namespace each time, you can write use App\Models\Product; at the Tinker prompt first. Creating Records > use App\Models\Product; > Product::create(['name' => 'Test Mouse', 'price' => 19.99]); Remember that create() requires the fields to be i...

Home · Projects · Articles · Developer tools · Contact