->createOptionUsing(function (array $data) { $subscription = Subscription::where('subject_id', $data['subject_id'])->where('subscription_year_id', $data['subscription_year_id'])->first(); if ($subscription) { return; } $subscription = new Subscription(); $subscription->subject_id = $data['subject_id']; $subscription->subscription_year_id = $data['subscription_year_id']; $subscription->federation_id = $data['federation_id']; $subscription->date = $data['date']; $subscription->price = $data['price']; $subscription->save(); return $subscription->id; })
$validator = Validator::make($data, [ Rule::unique('subscriptions')->where(function ($query) use($data) { ray('prova'); return $query->where('subject_id', $data['subject_id']) ->where('subscription_year_id', $data['subscription_year_id']); }), ]); if ($validator->fails()) { ray('ciao'); return null; }