Search code examples
phplaravelconstantsconfiglaravel-blade

How to use constant value inside blade file - Laravel


I want to use constant value inside blade file. I have svg tag in which I have<path> tag in which I want to use constant value.

I searched it online. I got this solution I got these solutions.

https://www.codegrepper.com/code-examples/php/get+constant+value+in+laravel https://stackoverflow.com/a/42155879/7290043

As suggested in the solution. I created a constants.php

<?php
return [

    // -------------- UI Constants
    
    'MAXIMIZE_SQAURE_ICON' => 'M14,15h-4v-2h3v-3h2v4C15,14.6,14.6,15,14,15z M13,3h-3V1h4c0.6,0,1,0.4,1,1v4h-2V3z M6,3H3v3H1V2c0-0.6,0.4-1,1-1h4V3z
    M3,13h3v2H2c-0.6,0-1-0.4-1-1v-4h2V13z'
];

I'm trying to use this MAXIMIZE_SQAURE_ICON value as d of <path> tag of blade file

<svg width="16" height="16">
  <path d="MAXIMIZE_SQAURE_ICON" /> 
</svg>

I also tried <path d = Config::get('constants.ADMIN_NAME') />

I'm not sure how to access it properly. I'm new to laravel.


Solution

  • You just need to call the constant in curly braces in your blade file like this:

    <svg width="16" height="16">
      <path d="{{ config('constants.MAXIMIZE_SQAURE_ICON') }}" /> 
    </svg>