当值为0或null laravel时重定向页面

问题描述 投票:0回答:2

我正在尝试将用户重定向到另一个页面,如果我的additional_infos表包含一些在这种情况下为空的东西,联系人,姓名,称呼和地址。

我现在有类似的东西:(基于我之前提出的问题,Redirect to page when value is null in another table laravel

但即使填写了联系人,称呼,姓名和地址,它仍会将我重定向到另一页。有人能帮我吗?提前致谢

Salutation是0而不是NULL,因为我使用下拉列表,所以如果我把它留空,它将返回0

public function test(Request $request){
    $additional_info = DB::table('additional_infos') 
                            ->whereNull('address')
                            ->orWhereNull('name')
                            ->orWhereNull('number')
                            ->orWhere('Salutation', 0)
                            ->get();
    //request input //ignore this part
    if( $additional_info->count())
        return redirect(url('/user/showupdate6/'.$id->id.'/edit6') );
    else{
    return redirect('/home');
}

如果我的数据名称,称呼,联系人和地址已填写,我希望它将我重定向到主页。如果我的数据名称,联系人和地址为空,我希望它将我重定向到此网址url('/user/showupdate6/'.$id->id.'/edit6')

php laravel redirect
2个回答
2
投票

使用empty()

if( empty($additional_info->count())){
    return redirect(url('/user/showupdate6/'.$id->id.'/edit6') );
}else{
    return redirect('/home');
}

1
投票

使用此代码:

public function test(Request $request){
         $additional_info = DB::table('additional_infos') 
                        ->whereNull('address')
                        ->orWhereNull('name')
                        ->orWhereNull('number')
                        ->orWhere('Salutation', 0)
                        ->get();
         //request input //ignore this part
        if( $additional_info->count() > 0)
           return redirect('/home');
        else{
           return redirect(url('/user/showupdate6/'.$id->id.'/edit6') );
         }
© www.soinside.com 2019 - 2024. All rights reserved.