mardi 24 novembre 2015

Laravel 5 One-to-many relationship master and parent data CRUD

I have a Purchase table with Date and Comments and a Purchasedetail table with PurchaseId as a foreign key of Purchase table. Have the relation in both model table is : purchase model:-

use Illuminate\Database\Eloquent\Model;
class Purchase extends Model {
public function purchasedetails() {
    return $this->hasMany('App\Models\Purchasedetail', 'PurchaseId', 'Id');
}
  }

and the Purchasedetail model :-

use Illuminate\Database\Eloquent\Model;
class Purchasedetail extends Model {
public function purchase() {
    return $this->belongsTo('App\Models\Purchase', 'PurchaseId', 'Id');
}
}

How can i create, update and delete both table data with relation? Main problem when i send data to controller and try to create , master page data created but can not create parent table data or update it . i am using Laravel 5 and i am new in it. it will be helpful if i find the solution.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire