没有得到条件 if 语句和 else 语句

Posted

技术标签:

【中文标题】没有得到条件 if 语句和 else 语句【英文标题】:Not getting condiotions if statement and else statement 【发布时间】:2021-11-30 02:41:53 【问题描述】:
$tickets  = Ticket::select("tickets.cust_id","tickets.ticket_id","tickets.category_id","tickets.subject","tickets.priority","tickets.message","tickets.status","tickets.createdticket","tickets.last_reply","tickets.closing_ticket","tickets.auto_close_ticket","tickets.created_at","tickets.updated_at","groups_categories.group_id","groups_users.users_id")
   ->leftJoin('groups_categories','groups_categories.category_id','tickets.category_id')
   ->leftJoin('groups_users','groups_users.groups_id','groups_categories.group_id')
   ->get();

以上代码是我的查询。我要根据登录用户显示票

【问题讨论】:

我认为你的标题和描述不相关。 laravel-4laravel-5,是哪个?您的代码中的 ifelse 语句在哪里? 【参考方案1】:

在您的 Laravel 查询中使用 where('groups_users.users_id', Auth::id()) 根据登录用户获取票证:

$tickets  = Ticket::leftJoin('groups_categories','groups_categories.id','tickets.category_id')
       ->leftJoin('groups_users','groups_users.id','groups_categories.group_id')
       ->select("tickets.cust_id","tickets.ticket_id","tickets.category_id","tickets.subject","tickets.priority","tickets.message","tickets.status","tickets.createdticket","tickets.last_reply","tickets.closing_ticket","tickets.auto_close_ticket","tickets.created_at","tickets.updated_at","groups_categories.group_id","groups_users.users_id")
       ->where('groups_users.users_id', Auth::id())
       ->get();

【讨论】:

以上是关于没有得到条件 if 语句和 else 语句的主要内容,如果未能解决你的问题,请参考以下文章

c语言中的 条件语句 if else

Python基础语法—— 条件语句(if)+循环语句(for+while)

R语言中的if else语句

Linux中if-else条件判断语句

对于互斥条件,多个“if”语句和“if-else-if”语句是不是相同?

JavaScript条件语句和循环语句