Laravel Web Tinker

Originally published at https://github.com

This package will add a route to your application where you can tinker to your heart's content.

In case light hurts your eyes, there's a dark mode too.

A word to the wise

This package can run arbritary code. Unless you know what you are doing, you should never install or use this in a production environment, or any environment where you handle real world data.

Installation

You can install the package via composer:

composer require spatie/laravel-web-tinker --dev

Next, you must publish the assets from this package by running this command.

php artisan web-tinker:install

Optionally, you can publish the config file of the package.

php artisan vendor:publish --provider="Spatie\WebTinker\WebTinkerServiceProvider" --tag="config"

This is the content that will be published to config/web-tinker.php

return [
/*
 * The web tinker page will be available on this path.
 */
'path' => '/tinker',

/*
 * Possible values are 'auto', 'light' and 'dark'.
 */
'theme' => 'auto',

/*
 * By default this package will only run in local development.
 * Do not change this, unless you know what your are doing.
 */
'enabled' => env('APP_ENV') === 'local',

/*
* This class can modify the output returned by Tinker. You can replace this with
* any class that implements \Spatie\WebTinker\OutputModifiers\OutputModifier.
*/
‘output_modifier’ => \Spatie\WebTinker\OutputModifiers\PrefixDateTime::class,

/*
 * If you want to fine-tune PsySH configuration specify
 * configuration file name, relative to the root of your
 * application directory.
 */
'config_file' => env('PSYSH_CONFIG', null),

];

Usage

By default this package will only run in a local environment.

Visit /tinker in your local environment of your app to view the tinker page.

Authorization

Should you want to run this in another environment (we do not recommend this), there are two steps you must perform.

  • You must register a viewWebTinker ability. A good place to do this is in the AuthServiceProvider that ships with Laravel.
public function boot()
{
$this->registerPolicies();

Gate::define('viewWebTinker', function ($user = null) {
    // return true if access to web tinker is allowed
});

}

  • You must set the enabled variable in the web-tinker config file to true.

Modifying the output

You can modify the output of tinker by specifying an output modifier in the output_modifier key of the web-tinker config file. An output modifier is any class that implements \Spatie\WebTinker\OutputModifiers\OutputModifier.

This is how that interface looks like.

namespace Spatie\WebTinker\OutputModifiers;

interface OutputModifier
{
public function modify(string $output = ‘’): string;
}

The default install of this package will use the PrefixDataTime output modifier which prefixes the output from Tinker with the current date time.

Testing

composer test

Thanks for reading

If you liked this post, share it with all of your programming buddies!

Follow me on Facebook | Twitter

Further reading

PHP with Laravel for beginners - Become a Master in Laravel

Projects in Laravel: Learn Laravel Building 10 Projects

Laravel for RESTful: Build Your RESTful API with Laravel

Laravel 5.8 Tutorial for Beginners

Fullstack Web Development With Laravel and Vue.js

Laravel 5.8 Ajax CRUD tutorial using Datatable JS

Laravel 5.8 Tutorial from Scratch for Beginners

Build RESTful API In Laravel 5.8 Example

Login with Google in Laravel 5.8 App using Socialite Package

Laravel PHP Framework Tutorial - Full Course for Beginners (2019)

#laravel #php #web-development

Laravel Web Tinker
31.65 GEEK