This is part of the series tinker like a boss (in psysh)

  1. tinker… what?
  2. includes
  3. casters (presenters)
  4. aliases
  5. http (and other) helpers
  6. wtf is this error?

Aliases

Class aliasing is very simple concept, that allows you to call a class by its alas, rather than original name. It’s not very common to use aliases when writing code , for your IDE gets you covered.

If you’re working with Laravel, it’s worth mentioning that all the facades are also aliases, that’s why you have things like request, validator etc available in global namespace. this is a convention introduced by Taylor to make things a bit more expressive,but still something that your IDE does for you.

As we know psysh offers TAB autocompletion, but still typing full namespaced class names gets tedious and unfortunately it doesn’t work will every class in your app. That’s wher custom aliases come in handy, because in REPL you type everything by yourself.

Using already mentioned .tinker include file, you can easily alias all the classes you need:

Of course we can do that at runtime as well:

 

If you didn’t check it yet, here is the psysh config file that I prepared for you.

Enjoy and share your thoughts in the comments below or on twitter @SOFTonSOFA

Now is the time to go to your console, type $ php artisan tinker and follow along

Laravel – tinker like a boss with PsySH from Jarek on Vimeo.

It's only fair to share...Tweet about this on TwitterShare on RedditPin on PinterestShare on FacebookShare on Google+

Related Post

Tinker like a boss – custom casters This is part of the series tinker like a boss (in psysh) tinker... what? includes casters (presenters) aliases http (and other) helpers ...
Tinker like a boss – custom includes This is part of the series tinker like a boss (in psysh) tinker... what? includes casters (presenters) aliases http (and other) helpers ...
Tinker like a boss (in psysh) tinker... what? includes casters (presenters) aliases http (and other) helpers wtf is this error? Tinker... what? REPL idea...
Querying relations in Laravel: get Models where la... Another part of Querying relations in Laravel will cover such problem: I want to get SomeModels that have latest RelatedModel (hasMany) matchin...