Today, We want to share with you Conditional When Case Statement in Laravel 6 Eloquent.In this post we will show you Laravel Eloquent – When Case Statement in Select Query Example, hear for Laravel 6 query with “if” conditions? we will give you demo and example for implement.In this post, we will learn about How to use if condition in laravel select query? with an example.
Conditional When Case Statement in Laravel 6 Eloquent
There are the Following The simple About Conditional Select Statement in laravel eloquent Full Information With Example and source code.
As I will cover this Post with live Working example to develop Using query builder or eloquent where adding statements with conditions, so the How to Create Multiple Where Clause Query Using Laravel Eloquent? is used for this example is following below.
Laravel 6 When Case Statement
Laravel SELECT Query:
$cars = \DB::table("cars") ->select("*", \DB::raw('(CASE WHEN cars.is_active = "0" THEN "Manager" WHEN cars.is_active = "1" THEN "Sellar" ELSE "Owner" END) AS active_lable')) ->get(); dd($cars);
Where IF condition in Laravel 6
$movies = Movie::where('bookmyshow', $movies_list) ->where('is_active', 0) ->orWhere('status', 1) ->whereRaw(" IF (final_movie_type = 'hindi', upcomming_movi, 7) LIKE concat('%', weekday('{$movies_list}'), '%') OR IF (final_movie_type = 'english', upcomming_movi, 0) = DAY('{$movies_list}') OR ( IF (final_movie_type = 'tamil', substring_index(upcomming_movi, '/', 1), 0) = DAY('{$movies_list}') AND IF (final_movie_type = 'gujrati', substring_index(upcomming_movi, '/', -1), 0) = MONTH('{$movies_list}') ) ")->get(); dd($movies);
How to use if condition in laravel select query?
if condition in laravel Eloquent Example
$cars = Car::select("*", \DB::raw('(CASE WHEN cars.is_active = "0" THEN "Manager" WHEN cars.is_active = "1" THEN "Sellar" ELSE "Owner" END) AS active_lable')) ->get(); dd($cars);
Eloquent when() conditional
Laravel 6 Eloquent when() conditional method:
Bookmyshow::query() ->when(Input::has('movi-id'), function ($query) { return $query->where('movi_id', Input::get('movi-id')); }) ->when(Input::has('type'), function ($query) use ($good, $poor) { return $query->whereBetween('tickets', [$good, $poor]); }) ->when(Input::has('find'), function ($query) { return $query->where('movie_title', 'LIKE', '%' . Input::get('find') .'%'); }) ->get();
condition based query in Laravel 6?
$query = DB::table('members'); if ($status == true) $query->where('status', '=', 1); if (isset($mrg_date)) $query->where('mrg_date', '>', $mrg_date); $result = $query->get();
Web Programming Tutorials Example with Demo
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about laravel select query when case condition.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.