samedi 30 avril 2016

Laravel Eloquent ORM: Change model so left join is *always* performed

I have a very simple Eloquent Model:

class HelpdeskComment extends Model
{
    protected $table   = 'helpdesk_comment';
    protected $guarded = ['id', 'helpdesk_topic_id'];

    public function topic () {
        return $this->belongsTo ('\\App\\Model\\HelpdeskTopic');
    }

    public function user () {
        return $this->belongsTo ('\\App\\Model\\User');
    }
}

This all works quite well when doing stuff like

$user = $helpdeskComment->user;

However, I would like to change the model so that the User table (specifically the "username" field) is always left-joined against the HelpdeskComment table, regardless of the query function called. Is there a simple/central way to achieve this or do I have to override each function (all(), etc.)?

Thanks for any ideas & pointers.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire