Model de kontrol edebilirsin yada bir validate yazabilirsin
$request->validate([
'slug' => [
'required',
function ($attribute, $value, $fail) {
if (YourModel::whereJsonContains('json_column->slug', $value)->exists()) {
$fail('The slug has already been taken.');
}
},
],
]);
use Illuminate\Database\Eloquent\Model;
use Illuminate\Validation\Rule;
class YourModel extends Model
{
protected $casts = [
'json_column' => 'array',
];
public static function boot()
{
parent::boot();
static::creating(function ($model) {
$slug = $model->json_column['slug'] ?? null;
if (YourModel::whereJsonContains('json_column->slug', $slug)->exists()) {
throw new \Exception("Slug değeri zaten mevcut: {$slug}");
}
});
}
}