Zubair Mukhtar
Zubair Mukhtar

Reputation: 320

Trying to get property 'id' of non-object using laravel

i am beginner at laravel,I am trying to update data but unfortunately i am facing error how to fix it ? Does anyone have an idea please help me thanks. please see this error https://flareapp.io/share/Lm839R5v

controller

  public function update(Request $request, $cms)
  {
       $cms = CMS::findOrFail($cms);
       $request->validate([
      'text'      => 'required',
       ]);

       $cms->text      = $request->text;
       $cms->type      = 16;
       $cms->save();
       return response()->json('Updated successfully', 200);
   }

Route

 Route::get('/pages/election','ElectionController@index')->name('about.elections');
 Route::put('/pages/election/{cms}/update', "ElectionController@update")- 
 >name('about.elctions.update');

Upvotes: 2

Views: 243

Answers (2)

omar jayed
omar jayed

Reputation: 868

It looks like $elections->id is the problem. Maybe there's no data in $elections and when you are trying to fetch id property, it can not find anything. That's where the error is.

Upvotes: 0

Alex
Alex

Reputation: 2775

As far as I see the problem is not in the controller code, problem is in election-js.blade.php at line 12:

axios.post('{{route('about.elctions.update',$elections->id)}}',

Which means you need to check $elections variable.

Upvotes: 1

Related Questions