i am taking make,model and fromyear and toyear from user i want to restrict if data with give fromyear and toyear range exsist in db
Like there is record with make=toyota ,model=camry ,fromyear=2015 ,toyear=2020 in db and then user enter then ranges like
2016-2017 or 2016-2018 or 2019 to 2022 or 2013 to 2016 so its restrict
and there is no fromyear and toyear is falling in range then its fine
DB columns name are make,model,fromyear,toyear
$has_range = PartsList::where('make', $request->make)
->where('model', $request->model)
->where(function ($query) use ($request)
{
$query->whereBetween('fromyear', [$request->fromyear, $request->toyear])
->orWhereBetween('toyear', [$request->fromyear, $request->toyear]);
})
->exists();
if($has_range)
{
$msg = 'year range already exists for this make and model';
}