首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用sql在laravel 8中使用未定义变量

使用sql在laravel 8中使用未定义变量
EN

Stack Overflow用户
提问于 2022-07-28 02:18:40
回答 1查看 43关注 0票数 0

我有一个问题,使用@if@elseif@else语句在blade.php上使用laravel 8,它总是作为未定义的变量返回。我如何解决这个问题?还是附近还有别的地方?

在我的index.blade.php

代码语言:javascript
复制
@if($exi)
@include('renew.modify.exi')
@elseif($exi2)
@include('renew.modify.exi2')
@elseif($exp)
@include('renew.modify.exp')
@endif

在我的modifyController.php

代码语言:javascript
复制
if (count((array) $exi) > 0) {
  return View::make('renew.modify.index', ['exi' => $exi]);
}
elseif(count((array) $exi2) > 0) {
  return View::make('renew.modify.index', ['exi2' => $exi2]);
}
elseif(count((array) $exp) > 0) {
  return View::make('renew.modify.index', ['exp' => $exp]);
} else {
  Session::flash('flash_message', 'Something went wrong on your credentials. Please double check your inputs. If you don\'t have any. You can create here: ');
  return Redirect::to('renewView');
}

我的目标是,当控制器检测到count((array) $something)检测时,它将返回到相同的index.blade,然后将触发@if, @elseif and @else,但当$exp检测到我的两个变量时,将是undefined。我如何解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-28 04:17:51

为此,可以使用isset()方法。像这样改变你的@if条件

代码语言:javascript
复制
@if(isset($exi))
@include('renew.modify.exi')
@elseif(isset($exi2))
@include('renew.modify.exi2')
@elseif(isset($exp))
@include('renew.modify.exp')
@endif

希望能帮上忙..。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73146516

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档