I have a many to many relation between Newsletter and Blocks. For this relation there is a pivot table named "block_newsletter". I've created a Pivot model for this relation because I need to put another OneToMany relation on this Pivot table/Model with my BlockItemContent table/Model.

This what my BlockNewsletterPivot Model looks like:

class BlockNewsletterPivot extends Pivot
{
    /**
     * The Block Item Content.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function blockItemContent()
    {
        return $this->hasMany('App\BlockItemContent');
    }
}

And this is my BlockItemContent model:

class BlockItemContent extends Model
{
    protected $table = 'block_item_content';

    protected $fillable = ['item_type', 'html_key', 'content', 'properties'];

    public $timestamps = false;

    /**
     * Get the BlockNewsletter item that owns the BlockItemContent.
     */
    public function blockNewsletterPivot()
    {
        return $this->belongsTo('App\BlockNewsletterPivot');
    }
}

Now I try to fetch it like this:

$blockNewsletterRow = BlockNewsletterPivot::findOrFail($blockNewsletterPivotId);

This results in the following error:

Argument 1 passed to Illuminate\Database\Eloquent\Relations\Pivot::__construct() must be an instance of Illuminate\Database\Eloquent\Model, none given

Here is a screenshot of my tables and relations to understand better maybe.

enter image description here

0 Answers