I get an error:
$count is undefined Make the variable optional in the blade template. Replace {{ $count }} with {{ $count?? '' }}
Here is my blade file:
@extends('layouts.layout')
@section('content')
<div class="container">
<br>
@if ($count == 0 && !$count == '')
<h3>Δε βρέθηκαν eshops με τον όρο αναζήτησης : <span class="badge badge-secondary">{{ $q }}</span>.
<br>
Θα κάνουμε ό,τι μπορούμε να καλύψουμε την ανάγκη σας !<h3>
<h5>Μπορείτε να δοκιμάσετε με ένα νέο όρο αναζήτησης ή επιβεβαιώστε την ορθογραφία σας.</h5>
<a href="{{ route('home') }}"><button type="button" class="btn btn-success">Δοκιμάστε πάλι !</button></a>
@else
<h3>Βρέθηκαν <span class="badge badge-secondary">{{ $count }}</span> eshops με τον όρο αναζήτησης : <span class="badge badge-secondary">{{ $q }}</span></h3>
@endif
@foreach($eshops as $eshop)
@include('includes.eshop')
<br>
@endforeach
</div>
@endsection
You could use the blade @isset
or @empty
as well:
@isset($count)
// $count is defined and is not null...
@endisset
@empty($count)
// $count is "empty"...
@endempty
More info can be found here: If Statements
Instead of {{ $count }}
try this {{ isset($count)? $count: ''}}
{{ isset($count)? $count: ''}}
// Try this method. {{(?empty($count)): $count : 'No Logs Found' }}
You can Try This.
@if(isset($count))
.....
@endif
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.