mercredi 16 mars 2016

Extending Eloquent model with different model

<?php

class Page extends Eloquent {

}

class Article extends Page {
    function __construct($attributes = []) {
        parent::__construct($attributes);
        $this->where('type', 'article');
    }
}

$articles = Article::all();
// SELECT * FROM pages WHERE type = 'article'

The page table has many types of data, I want to separate these data by model class, I tried the above query but where() function isn't even being called in __constructor()



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire