Problem to process the data of a query with Laravel

0

I get the data of: {% evento.data.categorias %} and I want to treat this information with php.

When I do the php echo "{% evento.data.categorias %}" the value is perfectly displayed, however I can not go through the string that is shown to check if there is a particular word within that string.

I suppose it will be because he does not recognize that it is a string? Does anyone know what I can do?

I do the following:

        <?php
            $mystring = "{% evento.data.categorias %}";
            $findme   = 'Promociones';
            $pos = strpos($mystring, $findme);

            if ($pos === false) {
                    echo "La cadena '$findme' no fue encontrada en la cadena '$mystring'";
                } else {
                    echo "La cadena '$findme' fue encontrada en la cadena '$mystring'";
                    echo " y existe en la posición $pos";
                }
        ?>

And I assure you that the word Promotions is within $ mystring

    
asked by Guillermo Armando Alvarez 28.09.2017 в 12:19
source

1 answer

0

I do not understand why you use the php tag in your code next to echo, I imagined that you were in a Blade template. If you want to keep your code clean, I recommend you read this article and make a Blade directive that you can use wherever you want.

link

So that you have something like this

@if(!strpos($evento.data.categories,"Promoción"))
   <b>No se encuentra</b>
@else
   <i>Se encontró una coincidencia</i>
@endif

If you do not want to make a php directive you can use your same code but between these directives

@php
//Código aquí
@endphp
    
answered by 28.09.2017 / 14:05
source