Skip to content

Instantly share code, notes, and snippets.

@goellner
Created May 23, 2023 17:37
Show Gist options
  • Save goellner/ea29ddeea50ef4e9cea4c513c0120b38 to your computer and use it in GitHub Desktop.
Save goellner/ea29ddeea50ef4e9cea4c513c0120b38 to your computer and use it in GitHub Desktop.
extend belongsto
<?php
namespace App\Nova\Fields;
use Laravel\Nova\Fields\BelongsTo as NovaBelongsTo;
use Laravel\Nova\Http\Requests\NovaRequest;
class BelongsTo extends NovaBelongsTo
{
public $component = 'belongs-to-with-facets';
public $hmm = null;
public function hmm(string $hmm)
{
$this->hmm = $hmm;
ray($this->hmm);
return $this;
}
public function jsonSerialize(): array
{
return with(app(NovaRequest::class), function ($request) {
$viewable = !is_null($this->viewable) ? $this->viewable : $this->resourceClass::authorizedToViewAny($request);
return array_merge([
'hmm' => $this->hmm,
'belongsToId' => $this->belongsToId,
'relationshipType' => $this->relationshipType(),
'belongsToRelationship' => $this->belongsToRelationship,
'debounce' => $this->debounce,
'displaysWithTrashed' => $this->displaysWithTrashed,
'label' => $this->resourceClass::label(),
'peekable' => $this->isPeekable($request),
'hasFieldsToPeekAt' => $this->hasFieldsToPeekAt($request),
'resourceName' => $this->resourceName,
'reverse' => $this->isReverseRelation($request),
'searchable' => $this->isSearchable($request),
'withSubtitles' => $this->withSubtitles,
'showCreateRelationButton' => $this->createRelationShouldBeShown($request),
'singularLabel' => $this->singularLabel,
'viewable' => $viewable,
], parent::jsonSerialize());
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment