File tree Expand file tree Collapse file tree
tests/Feature/Filament/Resources Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3030use Illuminate \Database \Eloquent \Builder ;
3131use Illuminate \Database \Eloquent \SoftDeletingScope ;
3232use Illuminate \Support \Str ;
33- use Livewire \Attributes \Url ;
3433
3534class PageResource extends Resource
3635{
@@ -48,12 +47,6 @@ class PageResource extends Resource
4847
4948 protected static ?string $ navigationLabel = 'Pages ' ;
5049
51- // /**
52- // * @var array<string, mixed> | null
53- // */
54- // #[Url()]
55- // public ?array $tableFilters = null;
56-
5750 public static function form (Form $ form ): Form
5851 {
5952 return $ form
@@ -82,7 +75,8 @@ public static function form(Form $form): Form
8275 ->searchable ()
8376 ->preload ()
8477 ->native (false )
85- ->columnSpan (1 ),
78+ ->columnSpan (1 )
79+ ->default (request ()->get ('sId ' )),
8680
8781 TextInput::make ('sef_key ' )
8882 ->label ('URL Slug ' )
@@ -171,8 +165,8 @@ public static function table(Table $table): Table
171165 {
172166 return $ table
173167 ->modifyQueryUsing (fn (Builder $ query ) => $ query ->when (
174- request ()->get ('section ' ),
175- fn (Builder $ q , $ sectionId ) => $ q ->where ('section_id ' , $ sectionId )
168+ request ()->get ('sId ' ),
169+ fn (Builder $ q , $ sId ) => $ q ->where ('section_id ' , $ sId )
176170 ))
177171 ->columns ([
178172 TextColumn::make ('title ' )
Original file line number Diff line number Diff line change @@ -15,8 +15,17 @@ class ListPages extends ListRecords
1515
1616 protected function getHeaderActions (): array
1717 {
18+ $ createAction = CreateAction::make ();
19+
20+ if (request ()->get ('sId ' )) {
21+ $ createAction
22+ ->url (fn () => PageResource::getUrl ('create ' , [
23+ 'sId ' => request ()->get ('sId ' ),
24+ ]));
25+ }
26+
1827 return [
19- CreateAction:: make () ,
28+ $ createAction ,
2029 ];
2130 }
2231}
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ public function getSectionNavigationItems(): array
2828 ->map (fn (Section $ section ): NavigationItem => NavigationItem::make ($ section ->getTranslation ('name ' , app ()->getLocale ()))
2929 ->url (
3030 fn (): string => PageResource::getUrl ('index ' , [
31- 'section ' => $ section ->id ,
31+ 'sId ' => $ section ->id ,
3232 ])
3333 )
3434 ->icon ('heroicon-o-arrow-turn-down-right ' )
Original file line number Diff line number Diff line change 161161 $ page1 = Page::factory ()->forSection ($ section1 )->create ();
162162 $ page2 = Page::factory ()->forSection ($ section2 )->create ();
163163
164- $ response = $ this ->get (PageResource::getUrl ('index ' ).'?section = ' .$ section1 ->id );
164+ $ response = $ this ->get (PageResource::getUrl ('index ' ).'?sId = ' .$ section1 ->id );
165165
166166 $ response ->assertSuccessful ();
167167 $ response ->assertSee ($ page1 ->title );
178178
179179 $ item = $ navigationItems [0 ];
180180 expect ($ item ->getLabel ())->toBe ('Test Section ' );
181- expect ($ item ->getUrl ())->toContain ('section = ' .$ section ->id );
181+ expect ($ item ->getUrl ())->toContain ('sId = ' .$ section ->id );
182182 expect ($ item ->getGroup ())->toBe ('CMS ' );
183183});
You can’t perform that action at this time.
0 commit comments