In my VendorsCrudController i make relation 1-n: ```
$this->crud->setModel('App\User');
$this->crud->addField([ // Address
'name' => 'vendor',
'type' => 'select',
'entity' => 'vendor', // the method that defines the relationship in your Model
'attribute' => 'name',
'model' => 'App\Dispensary',
]);
```
In User modal have method:
```
public function dispensaries() {
return $this->hasMany('App\Dispensary');
}
In Dispensary model:
public function vendor() {
return $this->belongsTo('App\User', 'user_id');
}
``` Table structure: (users) id: 1, name: Someone id: 2, name: Someone2 (dispensaries) id: 1, user_id: 1, name: SomeDispensary id: 2, user_id: 2, name: SomeDispensary
How to display products belonging to one user. Now I get all the products for one user
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire