There is a users table and tickets are linked by the users.id = tickets.create_by . To fetch a user from a particular ticket, I wrote the code:
class Ticket extends Model { protected $table = 'tickets'; public function user(){ return $this->hasOne('App\User','id','create_by'); } } use : Ticket::find(1)->user
How to implement a sample so that when writing Ticket::all()->withUsers() I can get a list of all tickets with users.
Addition to the question : At the moment there are many connecting fields ( foreign keys ) in the table, how to implement sampling through models so that the data on the keys are pulled together with the records ( tickets ). Of course, you can simply implement the request, but whether it will be correct and you don’t really want it because it’s sure that you can do better.
ps I will be glad to several options for solving this problem.