Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App;
  4.  
  5. use Illuminate\Database\Eloquent\Model;
  6.  
  7. class Category extends Model
  8. {
  9.     protected $table = 'category';
  10.    
  11.     protected $fillable = [
  12.         'title',
  13.     ];
  14.    
  15.     public function content()
  16.     {
  17.         return $this->hasOne('App\Category', 'category_id');
  18.     }
  19. }
  20. ?>
  21. --------------------------------------------------------------
  22. <?php
  23.  
  24. namespace App;
  25.  
  26. use Illuminate\Database\Eloquent\Model;
  27.  
  28. class Content extends Model
  29. {
  30.     protected $table = 'content';
  31.    
  32.     protected $fillable = [
  33.         'user_id', 'title', 'introText', 'text', 'photo', 'category_id', 'toDate', 'status', 'frontPage', 'created_at', 'updated_at'
  34.     ];
  35.    
  36.     public function category()
  37.     {
  38.         return $this->belongsTo('App\Content', 'id');
  39.     }
  40.    
  41.     public function similarContent() {
  42.         return $this->hasMany('App\SimilarContent');
  43.     }
  44.    
  45.     protected static function boot() {
  46.         parent::boot();
  47.  
  48.         static::deleting(function($content) { // before delete() method call this
  49.              $content->similarContent()->delete();
  50.              // do the rest of the cleanup...
  51.         });
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement