[英]How to make a variable optional in blade template (laravel 8)
I get an error:我收到一个错误:
$count is undefined Make the variable optional in the blade template. $count 未定义 使变量在刀片模板中成为可选。 Replace {{ $count }} with {{ $count??
将 {{ $count }} 替换为 {{ $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
或@empty
:
@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: ''}}
而不是
{{ $count }}
试试这个{{ isset($count)? $count: ''}}
{{ isset($count)? $count: ''}}
// Try this method. // 试试这个方法。 {{(?empty($count)): $count : 'No Logs Found' }}
{{(?empty($count)): $count : '未找到日志' }}
You can Try This.你可以试试这个。
@if(isset($count))
.....
@endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.