Laravel Tinker, re()loaded.
Reload your session from inside Tinker, plus magic shortcuts for first(), find(), where(), and more!
To install Tinx, simply require it via Composer:
composer require --dev ajthinking/tinx
If using Laravel <=5.4, register Tinx's service provider in config/app.php
(Laravel >=5.5 does this automatically):
<?php
// 'config/app.php'
return [
// etc…
'providers' => [
// etc…
Ajthinking\Tinx\TinxServiceProvider::class,
// etc…
],
// etc…
];
From the command line, instead of running php artisan tinker
, run:
php artisan tinx
To reboot your current session, simply call:
re()
This will allow you to immediately test out your application's code changes.
Aliases: reboot()
, reload()
, restart()
.
To regenerate Composer's optimized autoload files before rebooting your current session, call:
reo()
Calling reo()
simply runs composer dump -o
before re()
, ensuring any new classes added to your codebase since starting Tinx are automatically aliasable/resolvable by Laravel Tinker.
Tinx sniffs your models and prepares the following shortcuts:
Example Shortcut | Equals |
---|---|
$u |
App\User::first() |
$u_ |
App\User::latest()->first() |
$c |
App\Models\Car::first() |
u(3) |
App\User::find(3) |
u("gmail") |
Where "%gmail%" is found in any column. |
u("mail", "jon@snow.com") |
App\User::where("mail", "jon@snow.com")->get() |
u("id", ">", 0) |
App\User::where("id", ">", 0)->get() |
u() |
"App\User" |
u()::whereRaw(...) |
App\User::whereRaw(...) // Note: >= PHP 7.0 only |
Tinx calculates shortcut names via the implementation defined by your strategy
config value.
Lets say you have two models: Car
and Crocodile
.
If your naming strategy
was set to pascal
(default), Tinx would define the following shortcuts in your session:
- Car:
$c
,$c_
,c()
- Crocodile:
$cr
,$cr_
,cr()
The shortcuts defined for your session will display when Tinx loads and on subsequent reloads.
To see your shortcuts at any time during your session, run:
names()
Your shortcuts will initially display only if your session satisfies the names_table_limit
config value.
To filter the shortcuts returned by names()
, simply pass your filter terms like so:
names('car', 'user')