Home > Mobile >  How can I add "and" condition in laravel?
How can I add "and" condition in laravel?

Time:10-14

I want to add another condition to (L_Examen_Objectif::where('libelle', '=', $request->input('libelle') )->exists())

The condition If I get the same libelle has the same id it should return True (I don't want to insert the same libelle with the same id.)

Here is it my code:

 public function addPost(Request $request, $id)
 {
     if (L_Examen_Objectif::where('libelle', '=', $request->input('libelle') )->exists()) {
         return  'true';
     }
     else {
         $Examen_data = array(
             'libelle' => $request->input('libelle'),
             'id_examen' => $request->input('id_examen'),
             'id_lexamen' => $id,
         );
         L_Examen_Objectif::insert($Examen_data);    
     }
 }

CodePudding user response:

You can do it in more ways than one. One solution would be:

L_Examen_Objectif::where([
   ['libelle', '=', $request->input('libelle')],
   ['other_key', '=', $request->input('libelle')],
  ])

This is the pattern for this way:

$query->where([
    ['column_1', '=', 'value_1'],
    ['column_2', '<>', 'value_2'],
    [COLUMN, OPERATOR, VALUE],
    ...
])

More Information you will find here: How to Create Multiple Where Clause Query Using Laravel Eloquent?

  • Related