Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

How to make Condition based query in Laravel 5

by
Category:laravel
mysql laravel
How to make Condition based query in Laravel 5

So you're using laravel's query builder to get all orders that belong to a specific result using condition., but you want to allow the user to filter the results.

Now you can use model in your controllers.

use App\DiamondMaster;

Laravel query builder in if statement.

$getrecord = DiamondMaster::where('is_delete','0')
->where('C_Weight','>=',$request->min_carat)
->where('C_Weight','<=',$request->max_carat)
->where('C_DefthP','>=',$request->min_depth)
->where('C_DefthP','<=',$request->max_depth)
->where('C_NetD','>=',$request->min_price)
->where('C_NetD','<=',$request->max_price);	
if(!empty($request->shape))
{	
	$getrecord = $getrecord->whereIn('C_Shape',explode(",", $request->shape));
}
if(!empty($request->color))
{
	$getrecord = $getrecord->whereIn('C_Color',explode(",", $request->color));
}
if(!empty($request->clarity))
{
	$getrecord = $getrecord->whereIn('C_Clarity',explode(",", $request->clarity));
}
if(!empty($request->cut))
{
	$getrecord = $getrecord->whereIn('C_Cut',explode(",", $request->cut));
}
if(!empty($request->polish))
{
	$getrecord = $getrecord->whereIn('C_Polish',explode(",", $request->polish));
}
if(!empty($request->symmetry))
{
	$getrecord = $getrecord->whereIn('C_Symmetry',explode(",", $request->symmetry));
}
if(!empty($request->flourescence))
{
	$getrecord = $getrecord->whereIn('C_Fluorescence',explode(",", $request->flourescence));
}
if(!empty($request->flourescence))
{
	$getrecord = $getrecord->whereIn('C_Fluorescence',explode(",", $request->flourescence));
}
$getrecord = $getrecord->get();

0 Comments


Html code work in comment box


Related Post