【发布时间】:2013-09-06 02:48:13
【问题描述】:
我正在使用 Laravel 4,如果用户已登录,我会尝试传递信息。如果用户未登录,我想以纯文本形式显示其他内容
BookController
public function showIndex() {
$user_information = UsersInformation::find(Auth::user()->id);
return View::make('book.index', array('pageTitle' => 'Book your appointment', 'user_information' => $user_information));
}
我尝试在 $user_information 变量上方添加 isset() 但收到此错误消息
Cannot use isset() on the result of a function call
(you can use "null !== func()" instead)
Index.blade.php
@if (isset($user_information->first_name))
<p> You already have the 1 step complete let's move on to the second step!</p>
@else
<p>first step. let's create a login name and let's get to know you better</p>
@endif
在此处为名字添加了 isset,因为如果他们访问自己的帐户,则必须提供名字。
我尝试如下添加isset:
if (isset(UsersInformation::find(Auth::user()->id))) {
$user_information = UsersInformation::find(Auth::user()->id);
}
我当然尝试过使用推荐的语法,但随后再次出现“尝试获取非对象的属性”错误
【问题讨论】:
-
向我们展示您使用
isset()的实际代码,以及任何其他相关代码。 -
我编辑了我的问题。谢谢!
标签: php laravel laravel-4 isset