laravel if and code example

Example 1: laravel if syntax

@if (foo)
  // do something
@elseif (bar)
  // do something else
@else
  // do some other thing;
@endif

Example 2: if else statement in laravel blade

@if ($dummy == 1)    we have 1 record@elseif ($dummy ==10)    we have 10 record@else    No record found.@endif

Example 3: 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;