I am setting up an app where citizens can log tickets online to companies registered on our app. We have 5 types of User Roles
- [ App Super Admin, App Admin & App Support User ] ** Must see all logged tickets for all companies - [ Company Admin & Company Support User ] ** Must see only tickets for their company - [ App User ] ** Must see only their own logged tickets
Problem is that I see all tickets for all companies, irrespective of which user is logged-in.
I want the logged-in Company Support user or Company Admin to see only tickets logged for their company only and the app user who logged the ticket to only see their own tickets.
{
$companyUser = companyUser::findOrfail($user);
if (Auth::user()->id = $companyUser) {
$tickets = DB::table('tickets')
->join('company_users', 'company_users.company_id', '=', 'companies.id')
->join('tickets', 'ticket.company_id', '=', 'company_users.company_id')
->select(
'tickets.ref_no',
'tickets.service_id',
'tickets.ticket_subject_id',
'tickets.ticket_status_id',
'tickets.ticket_priority_id',
'tickets.company_id',
'tickets.user_id',
'tickets.created_at'
)
->where('company_users.user_id = users.id')
->get();
} else {
$tickets = DB::table('tickets')
->join('company_users', 'tickets.company_id', '=', 'company_users.company_id')
->select(
'tickets.ref_no',
'tickets.service_id',
'tickets.ticket_subject_id',
'tickets.ticket_status_id',
'tickets.ticket_priority_id',
'tickets.company_id',
'tickets.user_id',
'tickets.created_at'
)
->groupBy('ref_no')
->get();
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire