Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- class Category extends Model
- {
- protected $table = 'category';
- protected $fillable = [
- 'title',
- ];
- public function content()
- {
- return $this->hasOne('App\Category', 'category_id');
- }
- }
- ?>
- --------------------------------------------------------------
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- class Content extends Model
- {
- protected $table = 'content';
- protected $fillable = [
- 'user_id', 'title', 'introText', 'text', 'photo', 'category_id', 'toDate', 'status', 'frontPage', 'created_at', 'updated_at'
- ];
- public function category()
- {
- return $this->belongsTo('App\Content', 'id');
- }
- public function similarContent() {
- return $this->hasMany('App\SimilarContent');
- }
- protected static function boot() {
- parent::boot();
- static::deleting(function($content) { // before delete() method call this
- $content->similarContent()->delete();
- // do the rest of the cleanup...
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement