vendredi 29 juillet 2016

Laravel Conditional Statement: is when() efficient?

I would like to know about the efficiency / performance of using Laravel's new Conditional Statements when() that comes in the Query Builder functions.

Are they more efficient than a simple variable condition?

Example: i am filtering results with some radio and checkboxes, and they will provide many conditionals, i would like to know the most efficient way of applying them:

Simple conditional:

if($request->has('sale')) $query = $query->sale();

Laravel Conditional statement:

 query->when($request->has('sale'), function ($query){
     return $query->sale();
 })

Thanks in advance, cheers.

Docs: http://ift.tt/1rTRTqH



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire