我需要根据用户的状态重定向用户页面。我在Laravel 5.2中的My Controller中编写了一个方法,其中状态1正在工作但是当我添加else时,如果函数它在errror之后生成。
FatalErrorException in ProjectCollaboratorsController.php line 219: syntax error, unexpected 'return' (T_RETURN)
我的控制器方法如下
public function show($id){
if (Permission::where('status', 1)->where('project_id', $id)->exists())
{
$project = Project::find($id);
$tasks = $this->getTasks($id);
$files = $this->getFiles($id);
$comments = $this->getComments($id);
$collaborators = $this->getCollaborators($id);
$permissions = $this->getPermissions($id);
return view('collaborators.show');
}
else
{
(Permission::where('status', 2)->where('project_id', $id)->exists())
return view('collaborators.manager');
}
else if
{
(Permission::where('status', 3)->where('project_id', $id)->exists())
return view('collaborators.user');
}
}
答案 0 :(得分:0)
您的语法完全错误,请尝试使用此结构实现..
public function yourFunctionName()
{
if(condition1)
{
code
}
elseif(condition2)
{
code
}
else
{
code
}
}
答案 1 :(得分:0)
试试这段代码,你会很高兴
public function show($id){
if (Permission::where('status', 1)->where('project_id', $id)->exists())
{
$project = Project::find($id);
$tasks = $this->getTasks($id);
$files = $this->getFiles($id);
$comments = $this->getComments($id);
$collaborators = $this->getCollaborators($id);
$permissions = $this->getPermissions($id);
return view('collaborators.show');
}
else if(Permission::where('status', 2)->where('project_id', $id)->exists())
{
return view('collaborators.manager');
}
else if (Permission::where('status', 3)->where('project_id', $id)->exists())
{
return view('collaborators.user');
}
}