This commit is contained in:
Dan Harrin
2021-04-11 21:26:10 +01:00
parent 4a01dd832b
commit caa3ff00be
5 changed files with 31 additions and 17 deletions
+5 -7
View File
@@ -22,13 +22,6 @@ class Page extends Component
public static $view;
public function __invoke(Container $container, \Illuminate\Routing\Route $route)
{
abort_unless($this->isAuthorized(), 403);
return parent::__invoke($container, $route);
}
public static function authorization()
{
return [];
@@ -95,6 +88,11 @@ class Page extends Component
return Filament::can('view', static::class);
}
protected function abortIfForbidden()
{
abort_unless($this->isAuthorized(), 403);
}
public static function navigationItems()
{
return [
+2
View File
@@ -74,6 +74,8 @@ class CreateRecord extends Page
public function mount()
{
$this->fillRecord();
$this->abortIfForbidden();
}
protected function actions()
+17 -8
View File
@@ -68,6 +68,8 @@ class EditRecord extends Page
public function mount($record)
{
$this->fillRecord($record);
$this->abortIfForbidden();
}
public function save()
@@ -102,21 +104,28 @@ class EditRecord extends Page
];
}
protected function fillRecord($record)
protected function fillRecord($key)
{
$this->callHook('beforeFill');
$model = static::getModel();
$this->record = (new $model())->resolveRouteBinding($record);
if ($this->record === null) {
throw (new ModelNotFoundException())->setModel($model, [$record]);
}
$this->record = $this->resolveRecord($key);
$this->callHook('afterFill');
}
protected function resolveRecord($key)
{
$model = static::getModel();
$record = (new $model())->resolveRouteBinding($key);
if ($record === null) {
throw (new ModelNotFoundException())->setModel($model, [$key]);
}
return $record;
}
protected function form(Form $form)
{
return static::getResource()::form(
+5
View File
@@ -107,4 +107,9 @@ class ListRecords extends Page
'records' => $this->getRecords(),
];
}
public function mount()
{
$this->abortIfForbidden();
}
}
+2 -2
View File
@@ -85,7 +85,7 @@ class EditRecord extends Component
$this->record = [];
}
public function switchRecord($manager, $record)
public function switchRecord($manager, $recordKey)
{
if ($manager !== $this->manager) {
return;
@@ -93,7 +93,7 @@ class EditRecord extends Component
$this->callHook('beforeFill');
$this->record = $this->getQuery()->find($record);
$this->record = $this->getQuery()->find($recordKey);
$this->resetTemporaryUploadedFiles();
$this->callHook('afterFill');