Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/Console/TinkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ class TinkerCommand extends Command
*/
protected $description = 'Interact with your application';

/**
* Custom, user-defined casters for even better experience.
*
* @var array
*/
protected $casters = [];

/**
* Execute the console command.
*
Expand Down Expand Up @@ -102,7 +109,20 @@ protected function getCasters()
$casters['Illuminate\Foundation\Application'] = 'Laravel\Tinker\TinkerCaster::castApplication';
}

return $casters;
return array_merge($casters, $this->casters);
}

/**
* Set cusomized casters for this tinker session.
*
* @param array $casters
* @return $this
*/
public function setCasters(array $casters)
{
$this->casters = $casters;

return $this;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/TinkerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ class TinkerServiceProvider extends ServiceProvider
*/
public function register()
{
$this->app->singleton('command.tinker', function () {
return new TinkerCommand;
$this->app->singleton('command.tinker', function ($app) {
return (new TinkerCommand)->setCasters(
$app['config']->get('tinker.casters', [])
);
});

$this->commands(['command.tinker']);
Expand Down