Hope someone could help me updating my child table.I need to update need_status with a static value from Available to Taken.I must be missing something out here since I am new to laravel. Thank you in advance.
scholar_need_id  |  scholar_id | need_id  |  need_status
5                       1             2      Available 
6                       1             2      Taken
class Scholar extends Model { protected $primaryKey = 'scholar_id';     protected $fillable = [];
    public function needDetails(){
        //return $this->hasMany('App\ScholarNeed','scholar_need_id','scholar_id');
         return $this->hasMany('App\ScholarNeed','scholar_id','scholar_id');
    } }
--------------
class ScholarNeed extends Model {       protected $primaryKey = 'scholar_need_id';
    protected $fillable = ['scholar_id','need_id','need_status'];
    public function getNeedInfo(){
       // return $this->belongsTo('App\Scholar','scholar_id','scholar_need_id');
         return $this->belongsTo('App\Scholar','scholar_id','scholar_id');
    } }
------  public function update(Request $request,$recommend_id)
    {
       $id =  $request['scholar_id'];
     // $scholar = Scholar::find($id)->with('needDetails')->get();
      $scholarID = Scholar::with('needDetails')->find($id);
       $scholarID->needDetails()->need_status = 'Taken'; 
       $scholarID->save(); }
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire