lundi 28 mai 2018

Laravel show all records from table with joins

I want to show all records from my db in a table like this: enter image description here I have created this function but it doesn't recognize when I try to pass $ticket->id or any other column

public function index(){
       $ticket=Ticket::get();


        $user=DB::table(DB::raw('sarida_test.user AS db1_tb1'))
        ->join(DB::raw('task_flow.tickets AS db2_tb2'),'db1_tb1.Id','=','db2_tb2.user_id')
        ->where('db1_tb1.Id', '=', $ticket->user_id)->UserName;

        $priority = DB::table('priorities')
        ->join('tickets', 'priorities.id', '=', 'tickets.priority_id')
        ->select('priorities.*')
        ->where('priorities.id', '=',  $ticket->priority_id)
        ->title;


        $status = DB::table('status')
        ->join('tickets', 'status.id', '=', 'tickets.status_id')
        ->select('status.*')
        ->where('status.id', '=',  $ticket->status_id)
        ->title;
   return view('ViewTicket') ->with('ticket', $ticket)
    ->with('user', $user);

Basically how can I display all tickets with respective attributes! Thanks in advance!



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2IRKMfX
via IFTTT

Aucun commentaire:

Enregistrer un commentaire