title: How to link data from one table to another using Laravel 4?
body: <p>I have a customers migration table   </p>
  
  <pre><code>Schema::create('customers', function(Blueprint $table) {
      $table-&gt;increments('id');
      $table-&gt;string('name');
      $table-&gt;string('address');
      $table-&gt;string('phone');
      $table-&gt;string('email');
  });
  </code></pre>
  
  <p>and a tripsheet migration table which goes like this</p>
  
  <pre><code>Schema::create('tripsheets', function(Blueprint $table) {
      $table-&gt;increments('id');
      $table-&gt;integer('tripsheet_num');
      $table-&gt;integer('customer_id');
      $table-&gt;string('date');
      $table-&gt;string('customer_name');
      $table-&gt;string('customer_address');
      $table-&gt;string('customer_phone');
      $table-&gt;string('rep_address');
      $table-&gt;string('rep_phone');
  });
  </code></pre>
  
  <p>I have also created a customer eloquent,</p>
  
  <pre><code>class Customer extends Eloquent {
  
      public $timestamps = true;
      public $table = 'customers';
      protected $fillable = ['name', 'address', 'phone', 'email'];
  
      public function tripsheets(){
          return $this-&gt;belongsTo('Tripsheet', 'name', 'address', 'phone');
      }
  }
  </code></pre>
  
  <p>and a tripsheet model,</p>
  
  <pre><code>class Tripsheet extends Eloquent {
  
      public $timestamps = true;
      public $table = 'tripsheets';
      protected $fillable = [];
  
      public function customer(){
          return $this-&gt;hasMany('Customer', 'name', 'address', 'phone');
      }
  }
  </code></pre>
  
  <p>and my routes.php goes like this,</p>
  
  <pre><code>Route::get('/', function()
  {
      return View::make('hello');
  });
  
  Route::controller('/customers', 'CustomerController');
  Route::controller('/tripsheets', 'TripsheetController');
  </code></pre>
  
  <p>I would like to link the customer_name, customer_address, customer_phone from the tripsheet table to the name, address, phone of the customer table. I also want to know how to route them and fetch them as a json data to be used by angular JS to display the result.</p>
  
  <p>now should i create a third table to link these two? Or should i call it with <code>Customer::with('tripsheets')-&gt;all();</code>in the routes/controller?</p>
  
  <p>I also want to know how to route them and fetch them as a json data to be used by angular JS to display the result.?</p>