Use of undefined constant laravel

Updated 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