1

My laravel 5.5 project has 2 language (en and fr).

for each article, I write twice,one for fr,one for en

each article has an unique slug (but same slug for other language).

for eaxample:

example.com/fr/articleslug
example.com/en/articleslug 

I try validate it:

for store:

$validator = Validator::make($request->all(), [
    'slug' => 'nullable|unique:articles|max:250',

for update:

$validator = Validator::make($request->all(), [
'slug' => 'required|unique:articles,slug,'.$article->id.'|max:250',

you know with the top code,I could insert 'articleslug' only for one of languages.

Is it possible to check unique slug only for specific language?

here is my db table:

id /  title      /  text      / language / slug
1     en title     en test        en      articleslug
2     fr title     fr test       fr       articleslug
3     en title     en test       en      articleslug2
4     fr title     fr test       fr      articleslug2
Ali
  • 1,127
  • 1
  • 10
  • 23
  • There are a couple approaches. The one I've linked as duplicate is one of them. Another is writing a custom validator, which lets you do literally any validation logic you like. – ceejayoz Nov 15 '17 at 13:33

0 Answers0