1<?php
2
3namespace App;
4
5use Illuminate\Database\Eloquent\Model;
6
7class Image extends Model
8{
9 /**
10 * Get the owning imageable model.
11 */
12 public function imageable()
13 {
14 return $this->morphTo();
15 }
16}
17
18class Post extends Model
19{
20 /**
21 * Get the post's image.
22 */
23 public function image()
24 {
25 return $this->morphOne('App\Image', 'imageable');
26 }
27}
28
29class User extends Model
30{
31 /**
32 * Get the user's image.
33 */
34 public function image()
35 {
36 return $this->morphOne('App\Image', 'imageable');
37 }
38}
1class Mechanic extends Model
2{
3 /**
4 * Get the car's owner.
5 */
6 public function carOwner()
7 {
8 return $this->hasOneThrough(
9 'App\Owner',
10 'App\Car',
11 'mechanic_id', // Foreign key on cars table...
12 'car_id', // Foreign key on owners table...
13 'id', // Local key on mechanics table...
14 'id' // Local key on cars table...
15 );
16 }
17}