laravel / tinker

Powerful REPL for the Laravel framework.
https://laravel.com/docs/artisan#tinker
MIT License
7.34k stars 130 forks source link

allow adding custom casters and overriding laravel's own via config #39

Closed jarektkaczyk closed 6 years ago

jarektkaczyk commented 6 years ago

Hi!

This one allows adding custom and/or overriding laravel's own PsySH casters via array provided in config('tinker.casters')

=> Carbon\Carbon @1519569240 {#745
     +date: "2018-02-25 14:34:00.000000",
     +weekday: "Sunday",
     +day_of_year: 55,
     +unix: 1519569240,
     +diff_for_humans: "6 days ago",
   }
Setup ```php // config/tinker.php return [ 'casters' => [ // ordinary class-based method: Carbon\Carbon::class => 'App\Console\Casters::carbon', // or inline: Carbon\Carbon::class => function (Carbon\Carbon $carbon) { return [ 'date' => $carbon->date, 'weekday' => $carbon->format('l'), 'day_of_year' => (int) $carbon->format('z'), 'unix' => (int) $carbon->format('U'), 'diff_for_humans' => $carbon->diffForHumans(), ]; }, ], ]; ``` ```php namespace App\Console; class Casters { public static function carbon(Carbon\Carbon $carbon) { return [ 'date' => $carbon->date, 'weekday' => $carbon->format('l'), 'day_of_year' => (int) $carbon->format('z'), 'unix' => (int) $carbon->format('U'), 'diff_for_humans' => $carbon->diffForHumans(), ]; } } ```
taylorotwell commented 6 years ago

No plans on adding this right now.

jarektkaczyk commented 6 years ago

Why is that?

On Mon, Mar 5, 2018, 22:01 Taylor Otwell notifications@github.com wrote:

Closed #39 https://github.com/laravel/tinker/pull/39.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/laravel/tinker/pull/39#event-1504162945, or mute the thread https://github.com/notifications/unsubscribe-auth/AGm5ssyV4TknPDvdcJFNbBitb-DTWfkRks5tbUUcgaJpZM4SbTb6 .

--

Jarek Tkaczyk

SOFTonSOFA

from Kraków, in Singapore

zachdecook commented 1 year ago

Implemented by https://github.com/laravel/tinker/pull/133 in late 2021 (v2.6.2).