2017 © Pedro Peláez
 

laravel tinx

Reload your Laravel Tinker session from inside Tinker, plus magic shortcuts for first(), find(), where(), and more!

image

ajthinking/tinx

Reload your Laravel Tinker session from inside Tinker, plus magic shortcuts for first(), find(), where(), and more!

  • Wednesday, April 11, 2018
  • by ajthinking
  • Repository
  • 11 Watchers
  • 249 Stars
  • 37,475 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 16 Forks
  • 2 Open issues
  • 33 Versions
  • 35 % Grown

The README.md

⛔️ Laravel Tinx (Deprecated)

No Maintenance Intended, (*1)

Laravel Tinx was archived on 12th December 2019 and is no longer maintained., (*2)

Looking for a reloadable version of Laravel Tinker?, (*3)

Save the following script as tinx.sh to your project root directory:, (*4)

#!/bin/sh
while true; do php artisan tinker; done

Run the script to launch a reloadable version of Tinker:, (*5)

$ . tinx.sh

While your Tinker session is running, press:, (*6)

  • Ctrl + D from an empty prompt to reload your session
  • Ctrl + C to exit your session

Can't see newly created classes in Tinker?, (*7)

Exit your Tinker session and run:, (*8)

$ composer dump -o

Thanks for loving Laravel, and thanks for digging Tinx., (*9)

Happy coding!, (*10)

🤓👋, (*11)


Laravel Tinx

Laravel Tinker, re()loaded., (*12)

Reload your session from inside Tinker, plus magic shortcuts for first(), find(), where(), and more!, (*13)

, (*14)

Contents

Installation

To install Tinx, simply require it via Composer:, (*15)

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):, (*16)

<?php

// 'config/app.php'

return [
    // etc…
    'providers' => [
        // etc…
        Ajthinking\Tinx\TinxServiceProvider::class,
        // etc…
    ],
    // etc…
];

Usage

From the command line, instead of running php artisan tinker, run:, (*17)

php artisan tinx

Reload your Tinker session

To reboot your current session, simply call:, (*18)

re()

This will allow you to immediately test out your application's code changes., (*19)

Aliases: reboot(), reload(), restart()., (*20)

To regenerate Composer's optimized autoload files before rebooting your current session, call:, (*21)

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., (*22)

Magic models

Tinx sniffs your models and prepares the following shortcuts:, (*23)

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

Naming strategy

Tinx calculates shortcut names via the implementation defined by your strategy config value., (*24)

Lets say you have two models: Car and Crocodile., (*25)

If your naming strategy was set to pascal (default), Tinx would define the following shortcuts in your session:, (*26)

  • Car: $c, $c_, c()
  • Crocodile: $cr, $cr_, cr()

Names

The shortcuts defined for your session will display when Tinx loads and on subsequent reloads., (*27)

To see your shortcuts at any time during your session, run:, (*28)

names()

Your shortcuts will initially display only if your session satisfies the names_table_limit config value., (*29)

To filter the shortcuts returned by names(), simply pass your filter terms like so:, (*30)

names('car', 'user')

Fast factories

Shortcut methods are a great way to create factory models fast., (*31)

// Instead of this…
factory(App\User::class)->create()

// …try substituting a shortcut method, like this:
factory(u())->create()

When tinkering, every keystroke counts!, (*32)

Configuration

Tinx contains a number of helpful configuration options., (*33)

To personalise your Tinx installation, publish its config file by running:, (*34)

php artisan vendor:publish --provider=Ajthinking\\Tinx\\TinxServiceProvider --force

Once published, edit config/tinx.php where appropriate to suit your needs:, (*35)

<?php

// 'config/tinx.php'

return [

    /**
     * Base paths to search for models (paths ending in '*' search recursively).
     * */
    'model_paths' => [
        '/app',
        '/app/Models/*',
        // '/also/search/this/directory',
        // '/also/search/this/directory/recursively/*',
    ],

    /**
     * Only define these models (all other models will be ignored).
     * */
    'only' => [
        // 'App\OnlyThisModel',
        // 'App\AlsoOnlyThisModel',
    ],

    /**
     * Ignore these models.
     * */
    'except' => [
        // 'App\IgnoreThisModel',
        // 'App\AlsoIgnoreThisModel',
    ],

    /**
     * Model shortcut naming strategy (e.g. 'App\User' = '$u', '$u_', 'u()').
     * Supported values: 'pascal', 'shortestUnique'
     * */
    'strategy' => 'pascal',
    /**
     * Alternatively, you may pass a resolvable fully qualified class name
     * implementing 'Ajthinking\Tinx\Naming\Strategy'.
     * */
    // 'strategy' => App\CustomNamingStrategy::class,

    /**
     * Column name (e.g. 'id', 'created_at') used to determine last model shortcut (i.e. '$u_').
     * */
    'latest_column' => 'created_at',

    /**
     * If true, models without database tables will also have shortcuts defined.
     * */
    'tableless_models' => false,

    /**
     * Include these file(s) before starting tinker.
     * */
    'include' => [
        // '/include/this/file.php',
        // '/also/include/this/file.php',
    ],

    /**
     * Show the console 'Class/Shortcuts' table for up to this many model names, otherwise, hide it.
     * To always view the 'Class/Shortcuts' table regardless of the model name count,
     * pass a 'verbose' flag when booting Tinx (e.g. "php artisan tinx -v"),
     * or set this value to '-1'.
     * */
    'names_table_limit' => 10,

];

Contributing

Please post issues and send PRs., (*36)

License

MIT, (*37)

The Versions

11/04 2018

dev-master

9999999-dev

Reload your Laravel Tinker session from inside Tinker, plus magic shortcuts for first(), find(), where(), and more!

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

11/04 2018

v2.1.6

2.1.6.0

Reload your Laravel Tinker session from inside Tinker, plus magic shortcuts for first(), find(), where(), and more!

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

19/03 2018

v2.1.5

2.1.5.0

Reload your Laravel Tinker session from inside Tinker, plus magic shortcuts for first(), find(), where(), and more!

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

19/03 2018

2.1.3

2.1.3.0

Inject cool stuff into Laravel Tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

19/03 2018

v2.1.4

2.1.4.0

Inject cool stuff into Laravel Tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

16/03 2018

v2.1.2

2.1.2.0

Inject cool stuff into Laravel Tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

20/02 2018

v2.1.1

2.1.1.0

Inject cool stuff into Laravel Tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

20/02 2018

v2.1.0

2.1.0.0

Inject cool stuff into Laravel Tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

13/01 2018

v2.0.7

2.0.7.0

Inject cool stuff into Laravel Tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

26/12 2017

v2.0.6

2.0.6.0

Inject cool stuff into Laravel Tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

08/12 2017

v2.0.5

2.0.5.0

Inject cool stuff into Laravel Tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

07/12 2017

v2.0.4

2.0.4.0

Inject cool stuff into Laravel Tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

07/12 2017

v2.0.3

2.0.3.0

Inject cool stuff into Laravel Tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

03/12 2017

v2.0.2

2.0.2.0

Inject cool stuff into Laravel Tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

26/11 2017

v2.0.1

2.0.1.0

Inject cool stuff into Laravel Tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

14/11 2017

v2.0.0

2.0.0.0

Inject cool stuff into Laravel Tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

13/11 2017

v1.0.1

1.0.1.0

Inject cool stuff into Laravel Tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

12/11 2017

v1.0.0

1.0.0.0

Inject cool stuff into Laravel Tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

04/11 2017

v0.8.4

0.8.4.0

Inject cool stuff into laravels tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

31/10 2017

v0.8.3

0.8.3.0

Inject cool stuff into laravels tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

28/10 2017

v0.8.2

0.8.2.0

Inject cool stuff into laravels tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

28/10 2017

v0.8.1

0.8.1.0

Inject cool stuff into laravels tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

26/10 2017

v0.8

0.8.0.0

Inject cool stuff into laravels tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

26/10 2017

v0.7.1

0.7.1.0

Inject cool stuff into laravels tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

26/10 2017

v0.7

0.7.0.0

Inject cool stuff into laravels tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

26/10 2017

dev-feature/tableless-models

dev-feature/tableless-models

Inject cool stuff into laravels tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anders Jurisoo

24/10 2017

v0.6.1

0.6.1.0

Inject cool stuff into laravels tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

by Anders Jurisoo

24/10 2017

v0.6

0.6.0.0

Inject cool stuff into laravels tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

by Anders Jurisoo

23/10 2017

v0.5

0.5.0.0

Inject cool stuff into laravels tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

by Anders Jurisoo

22/10 2017

v0.4

0.4.0.0

Inject cool stuff into laravels tinker and make it restartable.

  Sources   Download

MIT

The Requires

 

by Anders Jurisoo

20/10 2017

v0.3

0.3.0.0

Inject cool stuff into laravels tinker and make it restartable.

  Sources   Download

MIT

by Anders Jurisoo

19/10 2017

0.1

0.1.0.0

Inject cool stuff into laravels tinker and make it restartable.

  Sources   Download

MIT

by Anders Jurisoo

19/10 2017

v0.2

0.2.0.0

Inject cool stuff into laravels tinker and make it restartable.

  Sources   Download

MIT

by Anders Jurisoo