Thursday, May 10, 2018

Check if record exist and return a boolean and compare it with inputs from a form - development

Check if record exist and return a boolean and compare it with inputs from a form

Hi i am having troubles sorting this out as the title says i am trying to check if a record exist and return a boolean instead of the record value from the database so i can compare it with a filter form, i know this can be solved using nested if’s but i’m trying to find a better way, this is my code so far

public function getSend(){
            if($this->request->role==1){
                $id= Cv::select('cv.user_id','cv.pub')
                    ->where('cv.pub','==',$this->request->pub)
                    ->get();
                dd($id);


                return view('gestione.'.$this->view_namespace.'.send.pagina');
            }

my idea is something like this

->where('cv.pub','==',$this->request->pub)

this one works because “pub” stores a boolean record in my database alot of other records store strings for example

->where('cv.something','==',$this->request->something)

wouldnt work because “something” is a string and not a boolean so how do i turn “something” into a boolean based on if wheter exist or not

thanks in advance by the way i am using laravel 5.1



from Laravel Questions and Answers https://laravelquestions.com/php/check-if-record-exist-and-return-a-boolean-and-compare-it-with-inputs-from-a-form/
via Lzo Media

No comments:

Post a Comment