vendredi 8 janvier 2021

laravel json select customer object select perticular data using hasMany

how to select customer object select perticular data

model user has connected to customer hasMnay

 public function customer()
    {
        return $this->hasMany('App\Models\Customer','employe_id','id');
    }

and user controller

$collection = User::with('customer')->where(['director_id'=> 16])->select('id','name',)->get();
        return $collection;

and response

[
    {
        "id": 25,
        "name": "emp1",
        "customer": [
            {
                "id": 9,
                "shop_owner_name": "afs",
                "email": "a@gmail.com",
                "address": "a",
                "lat_lng": "a",
                "shop_name": "a",
                "shop_license": "a",
                "contact_number": "1234567890",
                "shop_image": "image/rU54qz67G9pJ7xEc8JSMkZAzxgUE5pb98zQPelMt.png",
                "customer_image": "image/0ylk6OfMGwOqsdcUXpVZapOpPL73oO0gtOk7PXYV.png",
                "director_id": 0,
                "employe_id": 25
            },
            
        ]
    },
]


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire