Use of undefined constant laravel

Created at 20-May-2021 , By samar

Use of undefined constant laravel

Through many examples, we will learn how to resolve the "Use of undefined constant laravel".

You got this error message, Use of undefined constant if the string missing quotes and the variable missing the dollar symbol. Without quotes or dollar symbol PHP treats it as a constant which does not exist then it gives an error message.
  • Solved undefined constant error in laravel view using single quotes

    //Code with errorĀ 
    //misssing single quotes
    {{ $post->created_at->format(Y-m-d) }}
    //Code with solution
    // add single quotes while passing value to format method
    {{ $post->created_at->format('Y-m-d') }}

    You have to pass a value with a single quote in the method. This error occurs because laravel treats it as a constant name because you did not pass the value to the method with single or double quotes.

Back to code snippet queries related laravel

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.