Ad

Laravel 5.7 Exists/unique Validation With JSON Field Type

- 1 answer

I have a "countries" table with the following fields:

id: integer
name: json

Field "name" stores value as:

{ "en": "Germany", "de": "Deutschland" }

I wrote the following rule:

'country' => 'nullable|string|max:255|exists:countries,name->en'

but it doesn't work like that. How do I make it work?

MariaDB 10.1.36 / Laravel 5.7

Ad

Answer

Laravel 5.7 doesn't support JSON queries on MariaDB. This will be fixed in Laravel 5.8.

In the meantime, you can use this package: https://github.com/ybr-nx/laravel-mariadb

Ad
source: stackoverflow.com
Ad