Dev Diaries WD logo Dev Diaries WD
LARAVEL INTERVIEW · EP 02
LARAVEL INTERVIEW · Episode 02

Laravel: Tinker (the interactive REPL)

Run live Laravel code from your terminal — no route, no browser

terminal — php artisan tinker
# Start the REPL
php artisan tinker

# Create a row (uses the employees table from LEP 01)
>>> use App\Models\Employee;
>>> Employee::create([
...     'name'       => 'Asha Rao',
...     'age'        => 29,
...     'email'      => 'asha@example.com',
...     'address'    => '12 MG Road',
...     'department' => 'Engineering',
... ]);

# Read it back
>>> Employee::count();
>>> Employee::where('department', 'Engineering')->get();

# Bulk-create with the factory
>>> Employee::factory()->count(3)->create();
Output

Psy Shell (PHP 8.3) — type help for help.

>>> Employee::create([...]);

=> App\Models\Employee { id: 1, name: "Asha Rao", department: "Engineering" }

>>> Employee::count();

=> 1

>>> Employee::factory()->count(3)->create();

=> Illuminate\Database\Eloquent\Collection (3 items)