samedi 19 mars 2016

Laravel5 how to do a multi-condition query with if clause

I am a beginner, and currently creating a laravel project which needs multi-condition query like this:

view layer sample enter image description here

Each of these three conditions could be blank.

If one is blank, the corresponding controller should not add 'where clause' when querying the db.

I know in java, I can apply if clause to this like:

String sql = "select field from table where 1 = 1";
if(a!=null&&!a.isEmpty())
  sql+=" and a = '"+a+"'";
then execute sql......

but in laravel, how do i address this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire