Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

madsynn's avatar

3 Model Query Assistance

I need help getting this query built. For some reason, i am having difficulty and could use your assistance, please.

3 models = Product, Doc, Doctype

I need something along this:

select *  products 
where  
docs.config_catalog_filter == current  
with 
doctype->slug = mtype

and return the document

MY DB

products: id name description short slug type published
docs: id set_name industry published slug
doctype: id title slug

Product.php

    protected $fillable = [
        'published',
        'chicklet',
        'type',
        'demo_form',
        'demo_request_link',
        'name',
        'short',
        'description',
        'section_id',
        'slug',
        'created_at',
        'updated_at',
        'deleted_at',
    ];

    public function docs()
    {
        return $this->hasMany(Doc::class);
    }

Doc.php

    const CONFIG_CATALOG_FILTER_SELECT = [
        'current'      => 'Current Product',
        'discontinued' => 'Discontinued Product',
    ];

    protected $fillable = [
        'published',
        'config_catalog_filter',
        'set_name',
        'industry',
        'slug',
        'created_at',
        'updated_at',
        'deleted_at',
    ];

    public function doctypes()
    {
        return $this->belongsToMany(DocType::class);
    }


Doctype.php

    protected $fillable = [
        'title',
        'slug',
        'created_at',
        'updated_at',
        'deleted_at',
    ];

    public function doctypeDocs()
    {
        return $this->belongsToMany(Doc::class);
    }

0 likes
0 replies

Please or to participate in this conversation.