1. Home
  2. Laravel
  3. Join tables

Example of joining to collections using join function helper. First argument determines a table to join, the two following arguments select columns to make the join at.

return DB::table('users')
->join('messages', 'messages.from', 'users.id') // Select table to join and keys to make a join at
->select('from', 'name', 'text', 'messages.created_at' )
Full Laravel cheatsheet