laraning / nova-time-field

Laravel Nova Time Field
https://www.laraning.com
MIT License
64 stars 26 forks source link

Problem when retrieve data from MsSQL when field TIME(7) #61

Open netinhoteixeira opened 2 years ago

netinhoteixeira commented 2 years ago

When I edit on Nova the record with field TIME(7) from a Microsoft SQL Server, the value returns in following format:

H:i:s.Z

Example: 09:00:00.0000000

So, a error happens:

{
    "message": "Trailing data",
    "exception": "Carbon\\Exceptions\\InvalidFormatException",
    "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\nesbot\\carbon\\src\\Carbon\\Traits\\Creator.php",
    "line": 675,
    "trace": [
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\nesbot\\carbon\\src\\Carbon\\Traits\\Creator.php",
            "line": 698,
            "function": "rawCreateFromFormat",
            "class": "Carbon\\Carbon",
            "type": "::"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laraning\\nova-time-field\\src\\TimeField.php",
            "line": 39,
            "function": "createFromFormat",
            "class": "Carbon\\Carbon",
            "type": "::"
        },
        {
            "function": "Laraning\\NovaTimeField\\{closure}",
            "class": "Laraning\\NovaTimeField\\TimeField",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\nova\\src\\Fields\\Field.php",
            "line": 252,
            "function": "call_user_func"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\helpers.php",
            "line": 263,
            "function": "Laravel\\Nova\\Fields\\{closure}",
            "class": "Laravel\\Nova\\Fields\\Field",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\nova\\src\\Fields\\Field.php",
            "line": 253,
            "function": "tap"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\nova\\src\\Fields\\Field.php",
            "line": 221,
            "function": "resolve",
            "class": "Laravel\\Nova\\Fields\\Field",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\nova\\src\\ResolvesFields.php",
            "line": 95,
            "function": "resolveForDisplay",
            "class": "Laravel\\Nova\\Fields\\Field",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Collections\\Traits\\EnumeratesValues.php",
            "line": 234,
            "function": "Laravel\\Nova\\{closure}",
            "class": "Laravel\\Nova\\Resource",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\nova\\src\\ResolvesFields.php",
            "line": 97,
            "function": "each",
            "class": "Illuminate\\Support\\Collection",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\nova\\src\\ResolvesFields.php",
            "line": 179,
            "function": "detailFields",
            "class": "Laravel\\Nova\\Resource",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\nova\\src\\Resource.php",
            "line": 458,
            "function": "detailFieldsWithinPanels",
            "class": "Laravel\\Nova\\Resource",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\nova\\src\\Http\\Controllers\\ResourceShowController.php",
            "line": 27,
            "function": "serializeForDetail",
            "class": "Laravel\\Nova\\Resource",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Controller.php",
            "line": 54,
            "function": "handle",
            "class": "Laravel\\Nova\\Http\\Controllers\\ResourceShowController",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ControllerDispatcher.php",
            "line": 45,
            "function": "callAction",
            "class": "Illuminate\\Routing\\Controller",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php",
            "line": 254,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\ControllerDispatcher",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php",
            "line": 197,
            "function": "runController",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
            "line": 695,
            "function": "run",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 128,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\nova\\src\\Http\\Middleware\\Authorize.php",
            "line": 18,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Laravel\\Nova\\Http\\Middleware\\Authorize",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\nova\\src\\Http\\Middleware\\BootTools.php",
            "line": 20,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Laravel\\Nova\\Http\\Middleware\\BootTools",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\nova\\src\\Http\\Middleware\\DispatchServingNovaEvent.php",
            "line": 20,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Laravel\\Nova\\Http\\Middleware\\DispatchServingNovaEvent",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Middleware\\SubstituteBindings.php",
            "line": 50,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Routing\\Middleware\\SubstituteBindings",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Auth\\Middleware\\Authenticate.php",
            "line": 44,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\nova\\src\\Http\\Middleware\\Authenticate.php",
            "line": 31,
            "function": "handle",
            "class": "Illuminate\\Auth\\Middleware\\Authenticate",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Laravel\\Nova\\Http\\Middleware\\Authenticate",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken.php",
            "line": 78,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\View\\Middleware\\ShareErrorsFromSession.php",
            "line": 49,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\View\\Middleware\\ShareErrorsFromSession",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Session\\Middleware\\StartSession.php",
            "line": 121,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Session\\Middleware\\StartSession.php",
            "line": 64,
            "function": "handleStatefulRequest",
            "class": "Illuminate\\Session\\Middleware\\StartSession",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Session\\Middleware\\StartSession",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse.php",
            "line": 37,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\EncryptCookies.php",
            "line": 67,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Cookie\\Middleware\\EncryptCookies",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 103,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
            "line": 697,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
            "line": 672,
            "function": "runRouteWithinStack",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
            "line": 636,
            "function": "runRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
            "line": 625,
            "function": "dispatchToRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
            "line": 166,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 128,
            "function": "Illuminate\\Foundation\\Http\\{closure}",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\nova\\src\\Http\\Middleware\\ServeNova.php",
            "line": 26,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Laravel\\Nova\\Http\\Middleware\\ServeNova",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull.php",
            "line": 31,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TrimStrings.php",
            "line": 40,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TrimStrings",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize.php",
            "line": 27,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance.php",
            "line": 86,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\fruitcake\\laravel-cors\\src\\HandleCors.php",
            "line": 38,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Fruitcake\\Cors\\HandleCors",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\fideloper\\proxy\\src\\TrustProxies.php",
            "line": 57,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Fideloper\\Proxy\\TrustProxies",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 103,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
            "line": 141,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
            "line": 110,
            "function": "sendRequestThroughRouter",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "D:\\Customers\\monumenta\\bb\\tmj\\E_Sports_Api\\public\\index.php",
            "line": 52,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        }
    ]
}

Then I solved editing the file vendor/laraning/nova-time-field/src/TimeField.php and changed the code at Line 29:

    /**
     * Create a new field.
     *
     * @param string      $name
     * @param string|null $attribute
     * @param mixed|null  $resolveCallback
     *
     * @return void
     */
    public function __construct($name, $attribute = null, $resolveCallback = null)
    {
        parent::__construct($name, $attribute, $resolveCallback ?? function ($value) {
            if (is_null($value)) {
                return '';
            } else if (strpos($value, '.') > 0) {
                $pieces = explode('.', $value);
                $value = $pieces[0];
            }

            return Carbon::createFromFormat('H:i:s', $value)->format($this->format());
        });
    }
IbrahemElanany commented 2 years ago

I had the same problem and i solved it by just remove the casting of that field from laravel model