Support the ongoing development of Laravel.io →
posted 6 years ago
Last updated 2 years ago.
0

@Pt.Agus Setiawan thanks for your message but have you got an idea for my problem ?

0

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.

0

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

Last updated 6 years ago.
0

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

0

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 ;)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

doogie1 wyde22 Joined 22 Sep 2018

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.