Answers for "laravel update child"

PHP
1

laravel update child

// to update child records.

// Offer Modal 
public function project()
{
  return $this->belongsTo(Project::class, 'project_id');
}

// we are using -> since 1 project is belongs to many offer
$offer->project->update(
  [
    'projectstatus_id'  =>  6,
  ]
);

// Offer Modal 
public function offerTransactions()
{
  return $this->hasMany(Transaction::class, 'offer_id', 'id');
}

// we are using -> and () since 1 offer can have many transactions
$offer->offerTransactions()->update([
  'transaction_status'  => 'Approved',
]);


//Please, mention if there is better way/idea.
Posted by: Guest on October-13-2021

Code answers related to "laravel update child"

Browse Popular Code Answers by Language