Reload Your Laravel Tinker Session with Tinx

Reload Your Laravel Tinker Session with Tinx

Laravel Tinx is a new package by Anders Jürisoo that allows you to reload a Laravel Tinker shell from inside of tinker and gives you automatic shortcuts for things like first(), find(), and search().

After installing the package, you use Tinx with an artisan command:

php artisan tinx

The highlight feature of Tinx is the ability to update your Tinker session with the re() command:

$ php artisan tinx
Tinx - something awesome is about to happen.

>>> re()
Reloading your tinker session.

Tinx also prepares shortcut methods by sniffing your models and preparing some shortcuts. Here’s the shortcut ($u) for getting the first user (after you create at least one):

$ php artisan tinx

>>> factory('App\User', 10)->create();
=> App\User {#959
     name: "Florine Herzog",
     email: "",
     updated_at: "2017-10-24 03:10:11",
     created_at: "2017-10-24 03:10:11",
     id: 1,
>>> $u
=> {#919
     +"name": "example",
     +"email": "",

If you want to get a specific user based on ID, you can pass the id to the u() function:

$ php artisan tinx
>>> u()
=> "App\User"

>>> u(3)
=> App\User {#773
     id: 3,
     name: "Alicia Grant",
     email: "",
     created_at: "2017-10-24 03:13:47",
     updated_at: "2017-10-24 03:13:47",

Here are more examples of how it works from the readme:

Example usage Equals
$u App\User::first()
$c App\Models\Car::first()
u(3) App\User::find(3)
u("gmail") Where "gmail" is found in any column.
u() "App\User"
u()::where(...) App\User::where(...)

If you have more than one model starting with the same letter, for example, Pictures and Players, Tinx will give you $pi and $pl as the first record for each respective model. The accompanying helper functions for Pictures and Players would be pi() and pl().

Start using Tinx by visiting the official repository for more information and get some excellent additional abilities in a Laravel tinker session.

Filed in: Laravel Packages / packages


Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Software Developer
Remote (US & Canada)
😎 Laravel Developer
Jogg, Inc
Junior, Mid, and Senior Software Engineers. Laravel / Vue. Saint Petersburg, FL
Saint Petersburg, FL and Remote
Senior PHP Developer (Laravel)
The Interaction Design Foundation
Fullstack Laravel Engineer (Munich/Remote) 💻
Munich, Germany or Remote