lundi 26 février 2018

Laravel - Get Data of Multiple Tables

i would like make a select from two tables, clients and loans. The query (In MySQL syntax) would be something like this:

SELECT * FROM loans, clients WHERE loans.status = 1 AND loans.client_id = clients.id;

This are my models:

class Client extends Eloquent {
    public function loans()
    {
        $this->hasMany('App\Loan');
    }
}

class Loan extends Eloquent {
    public function clients()
    {
        $this->belongsTo('App\Client');
    }
}

How it would be the function using the eloquent model?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire