Search code examples
phplaravelcontrollerlaravel-4

Inputs bug in Laravel 4 project


Iam new to laravel and php and i lack experience.Im working to an already build project and there is bug that i cant fix in the "SeminarController" here is the code :

                if(Input::has('relative_link_titles')){
                $rldesc = Input::get('relative_link_titles');
                $rllinks = Input::get('relative_link_urls');
                $array = array_combine($rldesc,$rllinks);

                while($ar = current($array)){
                    $val = Relative_PackageLinks::where('relpl_desc',key($array))->get();
                    if(empty($val[0])){
                        $newlink = new Relative_PackageLinks();
                        $newlink->relpl_desc = key($array);
                        $newlink->relpl_packageid = $id;
                        $newlink->relpl_link = current($array);
                        $newlink->save();
                    }
                    next($array);
                }

                $result = Relative_PackageLinks::whereNotIn('relpl_desc',$rldesc)->delete();
            } else {
                Relative_PackageLinks::where('relpl_packageid',$id)->delete();
            }`

when i press save if the input 'relative_link_titles' have the same name it cleans all the table i dont understand why so anyone experienced with php and laravel will be a lot of help answering this.Thank u all !


Solution

  • I did it it was easy i just had to add where('relpl_packageid',$id)->to $result and to $val so the while loop check for everytime to a specific $id