Answers for "laravel where with if condition"

PHP
7

laravel if syntax

@if (foo)
  // do something
@elseif (bar)
  // do something else
@else
  // do some other thing;
@endif
Posted by: Guest on May-11-2020
0

laravel where condition with if

$query = DB::table('user_ads')
            ->join('ads', 'users_ads.ad_id', '=', 'ads.id')
            ->orderBy($column, $method);

if ($input['search']) {
    $query->where('short_description', $input['search']);
}

if ($input['category']) {
    $query->where('category', $input['category']);
}

$query->join('users', 'users_ads.user_id', '=', 'users.id')
    ->select('ads.id', 'ads.img1', 'ads.short_description', 'ads.category', 'ads.product', 'ads.price', 'users.city')

$result= $query->get();

return $result;
Posted by: Guest on September-13-2020
-2

laravel if else condition in query

$query = SocialMediaFeed::where('location_id', $location_id);
if(!$filters) {
    $query = $query->where('self', '<>', true);
} else {
    $query = $query->orWhere('self', true);
}
Posted by: Guest on July-22-2020

Code answers related to "laravel where with if condition"

Browse Popular Code Answers by Language