雄辩的启动不仅仅针对一个类激活

我正在使用雄辩的项目,我想删除文章。 问题是数据库很复杂。 有些文章有article_lvl1和article_lvl1有article_lvl2。 当我删除文章时,事件函数正常工作:</ p>

 &lt;?php 
namespace app \ model;

class Article extends \ Illuminate \ Database \ Eloquent \ Model \ n {
public static function boot()
{
parent :: boot();

//导致删除产品级联到子级,因此它们也被删除
static :: deletion(function ($ article)
{
$ article-&gt; ArticleNiveau1() - &gt; delete();
$ article-&gt; ArticleNiveau2() - &gt; delete();
});
} \ n
公共函数ArticleNiveau1()
{
返回$ this-&gt; hasMany('app \ model \ ArticleNiveau1','id_article');
}

公共函数ArticleNiveau2()
{
返回 $ this-&gt; hasMany('app \ model \ ArticleNiveau2','id_article');
}

保护$ table ='Article';
public $ timestamps = false;
protected $ primaryKey ='id_article';

}
</ code> </ pre>

但是文章也可以有article_Informations,可以有article_Date。 我的问题是引导函数中的所有内容在删除时都可以正常执行,但不能在article_Date中执行。 这是代码:</ p>

 &lt;?php 
namespace app \ model;

class Article_Informations extends \ Illuminate \ Database \ Eloquent \ Model
{
public function Article ()
{
返回$ this-&gt; belongsTo('app \ model \ Article','id_article');
}

公共函数ArticleNiveau1()
{
返回$ this-&gt; belongsTo('app \ model \ ArticleNiveau1','id_nv1');
}

公共函数ArticleNiveau2()
{
返回$ this-&gt; belongsTo('app \ model \ ArticleNiveau2','id_nv2' );

公共函数Article_Date()
{
返回$ this-&gt; hasMany('app \ model \ Article_Date','id_info');
}

公共静态函数启动( )
{
parent :: boot();

//导致删除产品以级联到子级,因此它们也会被删除
static :: deletion(function($ info)

\ n $ info-&gt; Article_Date() - &gt; delete();
});
}

保护$ table ='Article_Informations';
public $ timestamps = false;
protected $ primaryKey ='id_info' ;
}
</ code> </ pre>

我不知道为什么,它是唯一的偶数 t在删除时没有触发。
有人解释我吗?</ p>
</ div>

展开原文

原文

I'm using eloquent for a project and I would like to delete articles. The problem is that the database is complicated. There are articles, that have article_lvl1 and article_lvl1 have article_lvl2. When I delete an article the event functions work fine :

<?php
namespace app\model;

class Article extends \Illuminate\Database\Eloquent\Model
{
public static function boot()
{
    parent::boot();

    // cause a delete of a product to cascade to children so they are also deleted
    static::deleting(function($article)
    {
        $article->ArticleNiveau1()->delete();
        $article->ArticleNiveau2()->delete();
    });
}

public function ArticleNiveau1()
{
    return $this->hasMany('app\model\ArticleNiveau1', 'id_article');
}

public function ArticleNiveau2()
{
    return $this->hasMany('app\model\ArticleNiveau2', 'id_article');
}

protected $table = 'Article';
public $timestamps = false;
protected $primaryKey = 'id_article';
}

But an article can also have article_Informations, which can have article_Date. My problem is that everything in the boot functions executes fine on delete, but not the article_Date. Here is the code :

<?php
namespace app\model;

class Article_Informations extends \Illuminate\Database\Eloquent\Model
{
public function Article()
{
    return $this->belongsTo('app\model\Article', 'id_article');
}

public function ArticleNiveau1()
{
    return $this->belongsTo('app\model\ArticleNiveau1', 'id_nv1');
}

public function ArticleNiveau2()
{
    return $this->belongsTo('app\model\ArticleNiveau2', 'id_nv2');
}

public function Article_Date()
{
    return $this->hasMany('app\model\Article_Date', 'id_info');
}

public static function boot()
{
    parent::boot();

    // cause a delete of a product to cascade to children so they are also deleted
    static::deleting(function($info)
    {
        $info->Article_Date()->delete();
    });
}

protected $table = 'Article_Informations';
public $timestamps = false;
protected $primaryKey = 'id_info';
}

I don't know why, it's the only event that is not fired on delete. Can someone explain me ?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐