user()->can('create', Subscription::class); } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ 'product_id' => ['sometimes'], 'assigned_user_id' => ['sometimes'], 'is_recurring' => ['sometimes'], 'frequency_id' => ['sometimes'], 'auto_bill' => ['sometimes'], 'promo_code' => ['sometimes'], 'promo_discount' => ['sometimes'], 'is_amount_discount' => ['sometimes'], 'allow_cancellation' => ['sometimes'], 'per_set_enabled' => ['sometimes'], 'min_seats_limit' => ['sometimes'], 'max_seats_limit' => ['sometimes'], 'trial_enabled' => ['sometimes'], 'trial_duration' => ['sometimes'], 'allow_query_overrides' => ['sometimes'], 'allow_plan_changes' => ['sometimes'], 'plan_map' => ['sometimes'], 'refund_period' => ['sometimes'], 'webhook_configuration' => ['sometimes'], 'name' => Rule::unique('subscriptions')->where('company_id', auth()->user()->company()->id) ]; } protected function prepareForValidation() { $input = $this->all(); if(array_key_exists('webhook_configuration', $input) && (!is_object(json_decode($input['webhook_configuration'])))) $input['webhook_configuration'] = new \stdClass; if(!array_key_exists('webhook_configuration', $input)) $input['webhook_configuration'] = new \stdClass; $this->replace($input); } }