如果数据为空,则显示一条消息 [英] Showing a message if data is null laravel

查看:218
本文介绍了如果数据为空,则显示一条消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在刀片中显示一条消息,如果我的地址,名称或数字为空,请说此字段为空,请填写,如果已经填写,则什么也不显示.

I want to show a message in my blade where if my address, name or number is null say this fields are empty please fill them up, if there are filled already, just don't display anything.

目前,我确实喜欢这样,但是在blade.php中.以前我已经问过类似的问题,但是这次我想显示一条消息.我尝试按照提出的问题进行操作,但是由于某种原因,即使我的数据包含数据库中的值,它也会继续显示消息请填写它们".

Currrently I did like this, but in the blade.php. Previously I had already asked something similar but this time I want to show a message. I tried following the question that I asked but for some reason it keep showing the message "please fill them up" even though my data contain values inside the database.

在另一个表Laravel中,当值为null时重定向到页面

这是我的代码:

<?php 
     $additional_info = DB::table('additional_informations') 
                            ->whereNull('address')
                            ->orWhereNull('name')
                            ->orWhereNull('number')
                            ->get();
        if( $additional_info->count())
        echo "test";

 ?>

推荐答案

对于这样的路线:

Route::get('/userAddInfo/{id}/AddInfo','VerificationController@AddInfo');

您可以在方法中获取用户ID作为参数,然后在查询中使用它,如下所示:

You can get the user id in the method as parameter then use it in the query like this :

public function AddInfo($id) {
    $additional_info = DB::table('additional_informations')
                            ->where('user_id', $id)
                            ->where(function ($query) {
                                    $query->whereNull('EC_address')
                                          ->orWhereNull('EC_name')
                                          ->orWhereNull('EC_number');
                                })
                            ->get(); 
    return view('AddVerificationInfo',compact('id','additional_info')); 
}

在视图中:

@if($additional_info->count())
    "Please fill this up"
@endif

这篇关于如果数据为空,则显示一条消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆