lundi 14 décembre 2015

Composite Key validation in Laravel 5.1

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`);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire