So currently I pull back a date and convert it to a readable format in carbon:
</div>
<div class="">
<label for="Name">Letter Sent:</label>
@if (is_null($Client->letter_posted))
@else
{{ \carbon\carbon::createFromFormat('Y-m-d',$Client->letter_posted)->format('d/m/Y')}}
@endif
</div>
And it works when testing (Testing both whilst letter_posted is null and not) however very occasionally it will spit out the error on the live server:
Class 'carbon\carbon' not found
It has only occurred 3 times in the last 2 months very randomly and a refresh of the page will remove this error eg. the error appears, if you refresh the page it is no longer there.
Any help appreciated.
Change the code to:
{{ \Carbon\Carbon::createFromFormat('Y-m-d',$Client->letter_posted)->format('d/m/Y')}}
This happens when you deploy the system in a case sensitive server.
Most likely you are receiving the error because you're using carbon\carbon
somewhere in your code instead of \carbon\carbon
.
Putting the \
in front refers to the global namespace. Without the \
, you are referring to a class that might not exist (which is the error you are getting).
See: Class 'App\Carbon\Carbon' not found Laravel 5
You can create an alias to avoid using the full name in Laravel. In app.php
, go to aliases and add 'Carbon' => 'Carbon\Carbon'
. You can then use it like this:
{{ Carbon::createFromFormat('Y-m-d', $Client->letter_posted)->format('d/m/Y') }}
Additional note: while PHP namespaces are not case-sensitive, it is good practice to treat them as case-sensitive: use \Carbon\Carbon
instead of \carbon\carbon
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With