New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
2 participants
@jarektkaczyk

jarektkaczyk commented Mar 4, 2018

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
// 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(),
            ];
        },
    ],
];
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

This comment has been minimized.

Member

taylorotwell commented Mar 5, 2018

No plans on adding this right now.

@jarektkaczyk

This comment has been minimized.

jarektkaczyk commented Mar 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment