Php laravel检查它是否存在并发送警报

Php laravel检查它是否存在并发送警报,php,laravel-blade,laravel-6,Php,Laravel Blade,Laravel 6,我需要拉威尔的帮助 我需要得到一个运行:if并发送消息的代码: $text = App\Nota::select('nombre')->where('id', 3); 我需要检查,如果一个字符串='hello'到达,它将在.blade中打印一条消息 简而言之,检查它是否存在并发送警报 请帮帮我,你可以这样做 $text = App\Nota::select('nombre')->where('id', 3);if($text->nombre=="hello"){Sessio

我需要拉威尔的帮助

我需要得到一个运行:if并发送消息的代码:

 $text = App\Nota::select('nombre')->where('id', 3);
我需要检查,如果一个
字符串='hello'
到达,它将在.blade中打印一条消息

简而言之,检查它是否存在并发送警报


请帮帮我,你可以这样做

$text = App\Nota::select('nombre')->where('id', 3);if($text->nombre=="hello"){Session::flash('message', 'This is a message!');Session::flash('alert-class', 'alert-danger'); }
在视图中,可以使其显示如下

@if(Session::has('message'))<p class="alert {{ Session::get('alert-class', 'alert-info') }}">{{ Session::get('message') }}</p>@endif
@if(Session::has('message'))

{{Session::get('message')}

@endif
您可以这样做

$text = App\Nota::select('nombre')->where('id', 3);if($text->nombre=="hello"){Session::flash('message', 'This is a message!');Session::flash('alert-class', 'alert-danger'); }
在视图中,可以使其显示如下

@if(Session::has('message'))<p class="alert {{ Session::get('alert-class', 'alert-info') }}">{{ Session::get('message') }}</p>@endif
@if(Session::has('message'))

{{Session::get('message')}

@endif
如果您只想检查记录是否存在,请使用
exist()
方法尝试这种方法。在这里,在您的例子中,您只需要检查id为3的modal
Nota
,它的nombre列应该等于hello。无需加载模式,您可以尝试在
where()
方法中指定这两个条件,并使用
exist()
检查记录是否存在

控制器

$exist=App\Nota::where([
'id'=>3,
'nombre=>'hello'
])->存在();
如果(!$exist){
会话::flash('message','thisamessage!');
会话::flash(“警报级别”、“警报危险”);
}
查看

@if(会话::has('message'))

{ 会话::获取('message')}

@恩迪夫
如果您只想检查记录是否存在,请使用
exist()
方法尝试这种方法。在这里,在您的例子中,您只需要检查id为3的modal
Nota
,它的nombre列应该等于hello。无需加载模式,您可以尝试在
where()
方法中指定这两个条件,并使用
exist()
检查记录是否存在

控制器

$exist=App\Nota::where([
'id'=>3,
'nombre=>'hello'
])->存在();
如果(!$exist){
会话::flash('message','thisamessage!');
会话::flash(“警报级别”、“警报危险”);
}
查看

@if(会话::has('message'))

{ 会话::获取('message')}

@恩迪夫
您对此有何疑问?您对此有何疑问?