https://stackoverflow.com/questions/41051687/call-to-undefined-method-stdclasssave
This could help: Change your line $up = $dataCandidats::find($id); to something like this: $up = $flights = App\Candidats::where('id', '=' , $id) ->get();
"->save() will work only if the way that I retrieved the object(s) was via the model"
hope it helps.
No need to define new object of the model, just do this in update mehtod:
$up = Candidats::find($id);
$up->nom = $request->input('nomCandidat');
$up->prenom = $request->input('prenomCandidat');
$up->date = $request->input('dateCandidat');
$up->lieu_de_naissance = $request->input('lieuNaissance');
$up->experience = $request->input('nbrExperience');
$up->email = $request->input('emailCandidat');
$up->password = $request->input('pwdCandidat');
$up->save();
Also it is not good practise to return a view from update method it will be better to return a redirect respose
I think the solution of Cameron Audet is good. In my model i'm putting this code for my update :
public static function updateById($id, $data)
{
return DB::table('candidats')->where('id','=', $id)->update($data);
}
and my controller is here
$dataCandidats = new Candidats;
$up = $dataCandidats::updateById($id, $request->all());
return redirect('candidats.update')->with('update', 'Yesss!! Le candidat est modifie... ;)');
Now, i have got another error.
Column not found: 1054 Champ '_method' inconnu dans field list
For the update, i'm using method spoofing of laravek but it's a problem. I can create a special column in my database for "_method" and token ?
sorry but i don't understand
thanks so lot for your response
After few hours in my code, i'm resolving the problem. First, i modified my model with this code
public function updateById($id, $data = array())
{
return DB::table('candidats')->where('id', '=', $id)->update($data);
}
And after in my controller, i used this method :
$dataCandidats = new Candidats;
$dataCandidats->updateById($id, array(
'nom' => $request->input('nomCandidat'),
'prenom' => $request->input('prenomCandidat'),
'date' => $request->input('dateCandidat'),
'lieu_de_naissance' => $request->input('lieuNaissance'),
'experience' => $request->input('nbrExperience'),
'email' => $request->input('emailCandidat'),
'password' => $request->input('pwdCandidat')
)
);
return redirect('candidats/' . $id . '/edit')->with('update', 'Yesss!! Le candidat est modifie... ;)');
Cool, now relationship database...see you soon ;)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community