| 1 | <?php |
||
| 21 | class Supplier extends Eloquent\Model |
||
| 22 | { |
||
| 23 | use Eloquent\SoftDeletes; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * We do not want any timestamps. |
||
| 27 | * |
||
| 28 | * @var bool |
||
| 29 | */ |
||
| 30 | public $timestamps = false; |
||
| 31 | /** |
||
| 32 | * @var array |
||
| 33 | */ |
||
| 34 | protected $dates = ['deleted_at']; |
||
| 35 | /** |
||
| 36 | * The attributes that are mass assignable. |
||
| 37 | * |
||
| 38 | * @var array |
||
| 39 | */ |
||
| 40 | protected $fillable = ['name', 'location']; |
||
| 41 | |||
| 42 | 12 | public static function boot() |
|
| 43 | { |
||
| 44 | 12 | parent::boot(); |
|
| 45 | |||
| 46 | 12 | static::deleting(function (Supplier $supplier) { |
|
| 47 | 1 | $supplier->purchases()->delete(); |
|
| 48 | 12 | }); |
|
| 49 | 12 | } |
|
| 50 | |||
| 51 | /** |
||
| 52 | * Make a purchase. |
||
| 53 | * |
||
| 54 | * @param array $attributes |
||
| 55 | * |
||
| 56 | * @return Purchase |
||
| 57 | */ |
||
| 58 | 2 | public function makePurchase(array $attributes) |
|
| 62 | |||
| 63 | /** |
||
| 64 | * Purchases from this supplier. |
||
| 65 | * |
||
| 66 | * @return Eloquent\Relations\HasMany |
||
| 67 | */ |
||
| 68 | 3 | public function purchases() |
|
| 72 | } |
||
| 73 |