F
Filament15mo ago
Panda

Custom properties on Create Page causes 404

I'm passing the parent ID as route parameter and want to save it into a custom property named $series on the page but when I define the property on the CreatePage component it triggers a 404 error, when removed it works fine. So, I cannot define custom livewire state on my page or am I missing something?
<?php

namespace App\Filament\Resources\Content\ChapterResource\Pages;

use App\Filament\Resources\Content\ChapterResource;
use App\Models\Content\Series;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Routing\Exceptions\UrlGenerationException;

class CreateChapter extends CreateRecord
{
protected static string $resource = ChapterResource::class;

// THE FOLLOWING LINE GIVES 404 ERROR, WHEN REMOVED THE PAGE LOADS
public ?Series $series = null;

public function mount(): void
{
$series_id = request()->route('series');

if (!$series_id || !is_numeric($series_id))
throw new UrlGenerationException('Invalid series provided!');

dd($series_id);

$this->series = Series::findOrFail($series_id);

parent::mount();
}

/**
* {@inheritdoc}
*/
public function getBreadcrumbs(): array
{
return [];
}

protected function mutateFormDataBeforeCreate(array $data): array
{
dd($this->series);

$data['series_id'] = $this->series->id;

return $data;
}
}
<?php

namespace App\Filament\Resources\Content\ChapterResource\Pages;

use App\Filament\Resources\Content\ChapterResource;
use App\Models\Content\Series;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Routing\Exceptions\UrlGenerationException;

class CreateChapter extends CreateRecord
{
protected static string $resource = ChapterResource::class;

// THE FOLLOWING LINE GIVES 404 ERROR, WHEN REMOVED THE PAGE LOADS
public ?Series $series = null;

public function mount(): void
{
$series_id = request()->route('series');

if (!$series_id || !is_numeric($series_id))
throw new UrlGenerationException('Invalid series provided!');

dd($series_id);

$this->series = Series::findOrFail($series_id);

parent::mount();
}

/**
* {@inheritdoc}
*/
public function getBreadcrumbs(): array
{
return [];
}

protected function mutateFormDataBeforeCreate(array $data): array
{
dd($this->series);

$data['series_id'] = $this->series->id;

return $data;
}
}
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server