mercredi 1 février 2017

How to check if data exsists in the database so you can update it

This code above adds data to the database but it does not update if the data already exsists.

     public function updateStudentPastoral(){

   // Getting all post data
    $data = Input::all();


        $pCollection = new PastoralCollection();
        $pCollection->fill($data);
        $response = '';
        if ($pCollection->save())
            $response = 'success';
        else
            $response = 'error';

        return (json_encode($response));
 }

i want to check if the data already exists so i will update it in the database but if it does exist it will save in the database.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2jVxyAq
via IFTTT

Aucun commentaire:

Enregistrer un commentaire