I am trying the below query in Laravel 5.1
Select * from tblSubCategory
Where SubCategoryID != 1 and CategoryID = 1 and SubCategory = 'test data';
Below is my code in Laravel
$v = \Validator::make($request->all(), [
'SubCategory' => 'required|max:100|min:5|unique:tblsubcategory,SubCategory,'
.''.$request->input('CategoryID')
.',CategoryID,SubCategoryID,'.$request->input('SubCategoryID')
]);
Above expression is producing below query.
select count(*) as aggregate from `tblsubcategory`
where `SubCategory` = 'under website1' and `CategoryID` <> 1 and `SubCategoryID` = 1
Unique Key
UNIQUE KEY `UK_tblSubCategory_SubCategory_CategoryID` (`CategoryID`,`SubCategory`);
On the command line:composer require felixkiss/uniquewith-validator:2.*
Add the following to your providers array
in config/app.php
:
'providers' => array(
'Felixkiss\UniqueWithValidator\UniqueWithValidatorServiceProvider',
),
$v = \Validator::make($request->all(), [
'SubCategory' => 'required|max:100|min:5|unique_with:tblsubcategory,CategoryID',
'CategoryID' => 'required',
]);
$v = \Validator::make($request->all(), [
'SubCategory' => 'unique:tblsubcategory,SubCategory,'
.$request->input('SubCategoryID')
.',SubCategoryID,CategoryID,'
.$request->input('CategoryID')
]);
if ($v->fails()) {
return \Redirect::back()
->withErrors($v)
->withInput();
}