Call constant attributes of a class from laravel blade?

0

Hello, I have the next class

namespace App\Repository\Constants\Models;

class InstanceModelContant
{
    const ALREADY_DEMO = "Usted ya posee un demo.";
    const ALREADY_INSTANCE = "Ya tiene un servidor con estas caracteristicas.";
    const INSTANCE_DEMO_TYPE = "t2.micro";
    const CHAR_NOT_PUBLIC_ADDRESS = "--";
}

Within the class several constants were defined that I use in various places throughout the project.

In blade I have to make a comparison of the attribute of a model that would be like this

@if($instancia->publicip == '--')
                        {{$instancia->publicip}}
                    @else
                    <h1>hola mundo</h1>
                    @endif

But as you can see, I got to burn the code on - what I want is to use the CHAR_NOT_PUBLIC_ADDRESS attribute inside the blade and not burn the code.

Or what else could you advise me?

    
asked by FuriosoJack 25.10.2017 в 19:39
source

1 answer

0

It's not as complicated as you imagine, you can even show the text extracted from one of your constants and not just use it in your condition.

@if($instancia->publicip == App\Repository\Constants\Models\InstanceModelContant::CHAR_NOT_PUBLIC_ADDRESS)
    {{$instancia->publicip}}
@else
    <h1>hola mundo</h1>
@endif

//Si quisieras reemplazar el hola mundo por un valor extraido de la constante puedes usar
//{{ nombre_de_espacio_de_la_clase_que_contiene_la_constante::NOMBRE_DE_LA_CONSTANTE }}

I hope you were able to solve it. Greetings

    
answered by 25.10.2017 / 21:31
source