trueValue ? true : false) : null; } /** * Resolve the default value for the field. * * @return bool|null */ public function resolveDefaultValue(NovaRequest $request) { if ($request->isCreateOrAttachRequest() || $request->isActionRequest()) { return parent::resolveDefaultValue($request) ?? false; } } /** * Hydrate the given attribute on the model based on the incoming request. * * @param string $requestAttribute * @param \Illuminate\Database\Eloquent\Model|\Laravel\Nova\Support\Fluent $model * @param string $attribute * @return void */ protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute) { if (isset($request[$requestAttribute])) { $model->{$attribute} = $request[$requestAttribute] == 1 ? $this->trueValue : $this->falseValue; } } /** * Specify the values to store for the field. * * @param mixed $trueValue * @param mixed $falseValue * @return $this */ public function values($trueValue, $falseValue) { return $this->trueValue($trueValue)->falseValue($falseValue); } /** * Specify the value to store when the field is "true". * * @param mixed $value * @return $this */ public function trueValue($value) { $this->trueValue = $value; return $this; } /** * Specify the value to store when the field is "false". * * @param mixed $value * @return $this */ public function falseValue($value) { $this->falseValue = $value; return $this; } /** * Make the field filter. * * @return \Laravel\Nova\Fields\Filters\Filter */ protected function makeFilter(NovaRequest $request) { return new BooleanFilter($this); } /** * Prepare the field for JSON serialization. * * @return array */ public function serializeForFilter() { return transform($this->jsonSerialize(), function ($field) { return Arr::only($field, ['uniqueKey']); }); } }