mardi 20 mars 2018

User Multiple Relationships on a Single Laravel Query

I have Model Users with 2 hasMany relations like this

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Users extends Model
{
    protected $table='users';
    protected $primaryKey = 'id';

    public function clicks(){
        $this->hasMany(Clicks::class);
    }

    public function sales(){
        $this->hasMany(sales::class);
    }
}

Now i want to write a single laravel query to get count of clicks and sales made by users and also the sum from the sales.

Can anyone help in how to write this query?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2u3Acex
via IFTTT

Aucun commentaire:

Enregistrer un commentaire