gpt4 book ai didi

php - 如何在 Laravel 5.2 中比较行数据

转载 作者:行者123 更新时间:2023-11-29 20:30:40 24 4
gpt4 key购买 nike

我需要在 Laravel 中使用 AND 运算符检查我的表数据,并像这样查看

    if(Permission::where('status', '=', '1')->first()) AND (Permission::where('project_id', '=', '$id')->first())return view('collaborators.show')->withProject($project)->withTasks($tasks)->withFiles($files)->withComments($comments)->withCollaborators($collaborators);
else
return('hi');

但我收到以下错误

syntax error, unexpected 'else' (T_ELSE)

最佳答案

您在 if 之后和 return 关键字之前缺少括号。

这里有适合您的语法正确的代码:

if ((Permission::where('status', '=', '1')->first()) AND (Permission::where('project_id', '=', '$id')->first())) {
return view('collaborators.show')->withProject($project)->withTasks($tasks)->withFiles($files)->withComments($comments)->withCollaborators($collaborators);
} else {
return 'hi';
}
<小时/>

我不确定,但这也许就是您想要实现的目标

if (Permission::where('status', 1)->where('project_id', $id)->exists()) {
return view('collaborators.show')
->withProject($project)
->withTasks($tasks)
->withFiles($files)
->withComments($comments)
->withCollaborators($collaborators);
} else {
return 'hi';
}

关于php - 如何在 Laravel 5.2 中比较行数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39098201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com