public function saving($model) { $tmp_model = new \App\Destination(); // RULES $rules['destination_id'] = ['integer', 'min:1', 'exists:' . $tmp_model->getTable() . ',id']; $validator = Validator::make($model->toArray(), $rules); if ($validator->fails()) { dd('BelongsToDestinationObserver'); $model->setErrors($validator->messages()); return false; } }
public function saving($model) { $dest_model = new \App\Destination(); // RULES if (is_array($model->destination_ids)) { foreach ($model->destination_ids as $k => $v) { $rules['destination_ids' . $k] = ['exists:' . $dest_model->getTable()]; } } else { $rules['destination_ids'] = ['exists:' . $dest_model->getTable()]; } $validator = Validator::make($model->toArray(), $rules); if ($validator->fails()) { $model->setErrors($validator->messages()); return false; } }