How to make Laravel Tinker work in your Lumen app

florence
The Andela Way
Published in
2 min readSep 19, 2020

You’re here because you know what tinker is and you want to start using it with your Lumen app because, it’s not available right out of the box in Lumen, so lets get started already.

The Laravel documentation on artisan console shows how to get started but it’s silent about how to get it working in Lumen. https://laravel.com/docs/6.x/artisan#tinker

Step 1: Pull Laravel Tinker into your project with composer composer require laravel/tinker

Step 2: Suddenly realise, Oh no! This is not enough to get it working in Lumen!!! (This part is very important, you must act surprised else it wont work!)

Step 3: Don’t use vendor:publish it does not come with Lumen right out of the box too. If you had that working already in your app then lucky you, go ahead and use the vendor:publish command, else jump to the next step.

Step 4: Create a tinker.php file inside the config directory and paste the following code in it (if you ran the vendor:publish command successfully in the previous step, it would have created this file for you)

<?php

return [

/*
|--------------------------------------------------------------------------
| Console Commands
|--------------------------------------------------------------------------
|
| This option allows you to add additional Artisan commands that should
| be available within the Tinker environment. Once the command is in
| this array you may execute the command in Tinker using its name.
|
*/

'commands' => [
// App\Console\Commands\ExampleCommand::class,
],

/*
|--------------------------------------------------------------------------
| Auto Aliased Classes
|--------------------------------------------------------------------------
|
| Tinker will not automatically alias classes in your vendor namespaces
| but you may explicitly allow a subset of classes to get aliased by
| adding the names of each of those classes to the following list.
|
*/

'alias' => [
//
],

/*
|--------------------------------------------------------------------------
| Classes That Should Not Be Aliased
|--------------------------------------------------------------------------
|
| Typically, Tinker automatically aliases classes as you require them in
| Tinker. However, you may wish to never alias certain classes, which
| you may accomplish by listing the classes in the following array.
|
*/

'dont_alias' => [
'App\Nova',
],

];

Next: You must now register the TinkerServiceProvider in the bootstrap/app.php file.

...
$app->configure('tinker');
...
$app->register(\Laravel\Tinker\TinkerServiceProvider::class);

Finally, the tinker command is available for use. If you encounter any problems at this point, a simple composer dumpautoload might help.

Enjoy, share.

--

--

florence
The Andela Way

#Mum #AndelaAlumni #Backend Engineer #Mentor Book a 15 minutes session with me free of charge https://calendly.com/okosunuzflorence/15min