php - How can I build a condition based query in Laravel? - Stack Overflow

PHOTO EMBED

Tue Aug 03 2021 15:54:10 GMT+0000 (Coordinated Universal Time)

Saved by @mvieira #php

$query = DB::table('node');

if ($published == true)
    $query->where('published', '=', 1);

if (isset($year))
    $query->where('year', '>', $year);

$result = $query->get();
content_copyCOPY

https://stackoverflow.com/questions/14179758/how-can-i-build-a-condition-based-query-in-laravel