user()->can('create', Project::class); } public function rules() { $rules = []; $rules['name'] = 'required'; $rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id; if (isset($this->number)) { $rules['number'] = Rule::unique('projects')->where('company_id', auth()->user()->company()->id); } return $this->globalRules($rules); } protected function prepareForValidation() { $input = $this->decodePrimaryKeys($this->all()); if (array_key_exists('color', $input) && is_null($input['color'])) { $input['color'] = ''; } $this->replace($input); } public function getClient($client_id) { return Client::find($client_id); } }