Laravel If Else statement inside foreach -
i'm trying use if/else statement inside foreach loop. domdocument i'm trying find description tag , inside of description tag.
this works fine. when there description tag, display's what's inside description tag. if there no description tag displays: no description found no description found no description found no description found. why show error 4 times? how fix this?
i'm using domdocument , laravel 5.4
meta tag:
$meta = $dom->getelementsbytagname('meta');   my code:
@foreach ($meta $node)   @if($node->getattribute('name')=='description')      {{$node->getattribute('content'), php_eol}}       @else         {{'no description found'}}   @endif @endforeach   edit, according muthu17:
i have written same code you. problem is: shows "no description found" time. if finds description tag, show's description tag init , "no description found".
i've declared $showerrormessage = 0; in controller.
@foreach ($meta $node)  @if($node->getattribute('name')=='description')    {{$node->getattribute('content'), php_eol}}    @else     {!! $showerrormessage == 1; !!}    @endif @endforeach  @if($showerrormessage = 1)  {{'no description found'}} @endif      
hope looking this
<?php $showerrormessage = 0; ?> @foreach ($meta $node)   @if($node->getattribute('name')=='description')      {{$node->getattribute('content'), php_eol}}       @else         <?php $showerrormessage = 1;?>   @endif @endforeach  @if($showerrormessage == 0)  {{'no description found'}} @endif      
Comments
Post a Comment