guavacz / filament-nested-resources Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
When I create a record of a nested resource - in this case a page which is nested to a document - I get a 500 error as team_id isn't present on the nested resource table.
Documents are scoped to tenants but pages don't have to be as they belong to documents.
Create a resource and a nested resource. Set scopedToTenant as false on the nested resource.
1.0.0
8.3
10
macOS
I may be using the package wrong and if so please let me know what I should've done differently.
Thanks for an excellent plugin!
I should be able to get parent model to perform some queries
I did't find a way to get it while createing new nasted record
can't get parent model id
1.0.0-alpha.8
8.2
10.0
No response
No response
Query by ancestor is many duplicated.
public function getRelatedRecord(Model $record): ?Model
{
$relationship = $this->getInverseRelationship($record);
return $relationship->first();
}
i got this from AI and then its reduce 50% duplicated query
Just using debugbar and initialize nested resource like in filament page
newest
8.1
10
Windows
No response
Using global search on a root resource throws an error.
Configure a column to be globally searchable on the root resource. Then search for a record in that resource.
1.0.0-alpha.6
^8.1
^10
No response
I'm not sure if this is a user error or not. When I set up my root resource I didn't override the getAncestors method; it still returns null. So, when the getGlobalSearchResultUrl
method is called on the NestedResource
and it tries to search through its ancestors for their ids things blow up.
I have three tables
-campaigns (with id column)
-teams (with id column)
-campaigns_teams (pivot table with two foreign keys)
Now, I have a belongsToMany relationship set up on both Models, but I am getting an error when using this package.
Here is the error
Guava\Filament\NestedResources\Ancestor::getRelatedModel(): Return value must be of type Illuminate\Database\Eloquent\Model, Illuminate\Database\Eloquent\Collection returned
Create any many-to-many relationship and test this package.
v3.0.0-alpha8
8.1
10
No response
No response
My resource has a couple subnav items through ManageRelatedRecords, the links in the subnav are missing the resource's root parameter causing a 404. However, the routes themselves are fine and can be accessed otherwise.
https://filamentphp.com/docs/3.x/panels/resources/getting-started#resource-sub-navigation
1.0.0-alpha.9
8.3
10
Linux
No response
I get 404 error on /projects/1/tests
and /projects/1/tests/create
. I did everything according to the documentation and checked twice. Also the routes are listed in route:list
GET|HEAD app.mysite.test/projects/{record} .................................................................................................................................................................... filament.app.resources.projects.view › App\Filament\App\Resources\ProjectResource\Pages\ViewProject
GET|HEAD app.mysite.test/projects/{record}/tests ...................................................................................................................................................... filament.app.resources.projects.tests › App\Filament\App\Resources\ProjectResource\Pages\ManageProjectTests
GET|HEAD app.mysite.test/projects/{record}/tests/create ......................................................................................................................................... filament.app.resources.projects.tests.create › App\Filament\App\Resources\ProjectResource\Pages\CreateProjectTest
I tried the same with a different resource but the issue persists. I do not use any other traits or packages with my filament resources involved.
1.0
8.2
10.10
macOS, Linux
Any ideas on how to investigate this further?
I have a database where primaryKeys aren't "id", but "nID"
I can do laravel work with it simply using this statement in models:
protected $primaryKey = 'nID';
But when using nested-resources the urls that are generated doesn't have the parent levels nIDs on it (two slashes appear together)
I was guessing that the package assumes that primary key will be "id" and this returns a null value on my instances, so I tested a workaround in my models:
public function getIdAttribute() {
return $this->nID;
}
and it worked!
I hope this will help debuging the alfa package.
If you create or use a database with non-id primary keys you will experience the issue simply making a nested resource.
1.0@alpha
8.1.8
10.10
No response
No response
I am using models keyed by slug .. not by ID
when I acces root resource on url "http://localhost:8000/admin/categories/tocene-pivo"
button linkt to create new child item is "http://localhost:8000/admin/categories//items/create?category=tocene-pivo"
there is missing model slug "tocene-pivo" between categories and items
when I manualy try go to adress using slug "http://localhost:8000/admin/categories/tocene-pivo/items/create?category=tocene-pivo",
there is error
when I try manualy go to adress using ID "http://localhost:8000/admin/categories/1/items/create?category=tocene-pivo"
this adress work, but in adress and breadcrumbs is ID, instead of slug .. which is bad :(
use laravel models keyed by slug
1.0.0-alpha.4
8.2.11
10.28.0
Windows
No response
I had successfully implements an earlier version of this package. I was now trying to migrate to the 1.0.0 version. But i am not able to manage this yet.
Is there a example of the RelationManager implementation?
I would say i followed the steps of the documentation, but still have some issues.
Edit of a nested resource is now working. But it has a not nested url. Is this an intendent change or or am i missing some configuration?
Create is redirecting to a nested url but it is showing an 404 while the route is registered in laravel.
Looks like I'm missing some information. Could you help me to get it to work and probably improve the documentation for others as well?
class ArtistResource extends Resource
{
use NestedResource;
public static function getAncestor(): ?Ancestor
{
return null;
}
public static function getRelations(): array
{
return [
ArtistAlbumRelationManager::class,
];
}
//...
public static function getPages(): array
{
return [
'index' => Pages\ListArtists::route('/'),
'create' => Pages\CreateArtist::route('/create'),
'edit' => Pages\EditArtist::route('/{record}/edit'),
'albums.create' => CreateArtistAlbum::route('/{record}/albums/create'),
];
}
}
class ArtistAlbumResource extends Resource
{
use NestedResource;
public static function getAncestor(): ?Ancestor
{
return Ancestor::make('albums', 'artist');
}
//...
public static function getPages(): array
{
return [
'edit' => Pages\EditArtistAlbum::route('/{record}/edit'),
];
}
}
class CreateArtistAlbum extends CreateRelatedRecord
{
use NestedPage;
//...
}
class EditArtistAlbum extends EditRecord
{
use NestedPage;
//...
}
class ArtistAlbumsRelationManager extends RelationManager
{
use NestedRelationManager;
//...
}
1.0.0
8.3.0
11
No response
No response
I want to use the getModelLabel() function to set my translated labels, without interfering with this package.
The class Ancestor has the following function to get the relationship:
Ancestor.php
public function getRelationship(): string
{
if (! $this->relationship) {
return $this->getResource()::getModelLabel();
}
return $this->relationship;
}
Problem is, I'm using getModelLabel to translate the navigation items, as suggested by the Filament documentation...
Filament example
My code
public static function getModelLabel(): string
{
return ___('signeditor.signs', 1);
}
...which results in the relationship sign() being translated into Bord(), which does not exist 😛
1.0.0-alpha.5
8.2.11
10.30.0
Linux
No response
I cannot install package via composer - error
Could not find a version of package guava/filament-nested-resources matching your minimum-stability (stable). Require it with an explicit version constraint allowing its desired stability.
composer.json
"name": "laravel/laravel",
"type": "project",
"description": "The skeleton application for the Laravel framework.",
"keywords": [
"laravel",
"framework"
],
"license": "MIT",
"require": {
"php": "^8.1",
"amocrm/amocrm-api-library": "^1.4",
"awcodes/filament-tiptap-editor": "^3.0",
"codewithdennis/filament-select-tree": "^3.1",
"filament/filament": "^3.0-stable",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.3",
"laravel/scout": "^10.6",
"laravel/tinker": "^2.8",
"mohamedsabil83/filament-forms-tinyeditor": "^2.2",
"spatie/laravel-sitemap": "^7.0"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
"laravel/breeze": "^1.26",
"laravel/envoy": "^2.8",
"laravel/pint": "^1.0",
"laravel/sail": "^1.26",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^7.0",
"phpunit/phpunit": "^10.1",
"spatie/laravel-ignition": "^2.0"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi",
"@php artisan filament:upgrade"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"php-http/discovery": true
}
},
"minimum-stability": "stable",
"prefer-stable": true
}
composer require guava/filament-nested-resources
2
8.2.0
10
No response
No response
When you go to the view page, you can't click on the edit button because the URL is missing the parent of the nested resources URL param.
Create a nested resource. Navigate to a child resources' view page. Click on the edit button and you get a 404. If you are on the a edit page, the view button will take you to a 404 page too.
1.0.0-alpha.5
8.1.24
10.10
macOS
No response
I think that if we have a view page, the breadcrumbs should link to the view page (which is the default for clicking on the record itself), not the edit link that it is currently linking to.
Is there any way to overwrite it?
just make a nested rescource with the --view flag
3.x
8.3
10
No response
No response
composer require guava/filament-nested-resources
In PackageDiscoveryTrait.php line 331:
Could not find a version of package guava/filament-nested-resources matching your minimum-stability (stable). Require it with an explicit version cons
traint allowing its desired stability.
require [--dev] [--dry-run] [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--fixed] [--no-suggest] [--no-progress] [--no-update] [--no-install] [--no-audit] [--audit-format AUDIT-FORMAT] [--update-no-dev] [-w|--update-with-dependencies] [-W|--update-with-all-dependencies] [--with-dependencies] [--with-all-dependencies] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--] [...]
i had to use composer require guava/filament-nested-resources:dev-main
instead
default
8.2.1
10
No response
No response
If a field is live, when it is updated in a CreateRelatedRecord a "Typed property Guava\FilamentNestedResources\Pages\CreateRelatedRecord::$record must not be accessed before initialization" error is raised.
Set a field as live() and change its status.
1.0.0-beta.3
8.2.16
10.48.3
No response
Changing
$record = $this->record
with
$record = isset($this->record)
? $this->record
: $this->getOwnerRecord();
resolved the problem for me
I got an error when using morph relation:
Guava\Filament\NestedResources\Ancestor::getRelatedModel(): Return value must be of type Illuminate\Database\Eloquent\Model, null returned
Use these relevant codes, and try to open the edit program page, and it will be an error.
Relevant codes:
class Program extends Model
{
public function groups(): MorphMany
{
return $this->morphMany(Group::class, 'groupable', 'groupable_type', 'groupable_id', 'id');
}
}
class Group extends Model
{
public function groupable(): MorphTo
{
return $this->morphTo('groupable', 'groupable_type', 'groupable_id', 'id');
}
}
class ProgramResource extends NestedResource
{
protected static ?string $model = Program::class;
public static function getRelations(): array
{
return [
RelationManagers\GroupsRelationManager::class,
];
}
}
class GroupsRelationManager extends NestedRelationManager
{
protected static string $relationship = 'groups';
public function form(Form $form): Form
{
return GroupResource::form($form);
}
public function table(Table $table): Table
{
return GroupResource::table($table);
}
}
class GroupResource extends NestedResource
{
protected static ?string $model = Group::class;
public static function getAncestor(): ?Ancestor
{
// This is just a simple configuration with a few helper methods
return Ancestor::make(
ProgramResource::class, // Parent Resource Class
// Optionally you can pass a relationship name, if it's non-standard. The plugin will try to guess it otherwise
'groupable'
);
}
}
class CreateGroup extends NestedCreateRecord
{
protected static string $resource = GroupResource::class;
}
class EditGroup extends NestedEditRecord
{
protected static string $resource = GroupResource::class;
}
class ListGroups extends NestedListRecords
{
protected static string $resource = GroupResource::class;
}
1.0.0-alpha.5
8.2.10
10
No response
No response
When you are loading up the list view table, you see every record in the database instead of the records being filtered by their parent record.
Create a root resource and a corresponding child resource in your app. Create two root records RootA and RootB. On record A, navigate to the child resource and create a new record ChildA. Attempt to do the same for RootB. You will notice that when you are on the child resource for RootB, you will see that ChildA is visible in the table.
1.0.0-alpha.8
8.1
10
No response
I think the getTableQuery method needs to be extended in the NestedResource class.
When you have a nested resource that does not have a create page, the create action on the list page causes a route not found error.
Create a nested resource then comment out the create page route.
1.0.0-alpha.7
8.2
10
No response
I think the solution is to check to see if there is a create page on the resource before setting the action URL on the configureCreateAction
method.
if (static::getResource()::hasPage('create')) { $action->url(static::getResource()::getUrl('create', $this->getRouteParameterIds())); }
Hi, I have a CreateRelatedRecord
which uses the official Spatie Translatable plugin (https://filamentphp.com/plugins/filament-spatie-translatable).
How can I implement this for the CreateRelatedRecord
? I can't add the LocaleSwitcher to the CreateRelatedRecord class, because the ParentResource doesn't have any translations.
Have a nested resource where the nested resource has translatable properties.
ParentResource -> NestedResource (use Translatable)
1.0.0-beta.3
8.3.3
10.10
macOS
No response
When using SoftDeletes, ForceDeleteAction asks for an index route
Use a Resource with --soft-delete
enabled as Child.
1.0.0-alpha.8
8.3.0
10.10
macOS
No response
When I am trying to navigate to the create page I am getting the below error.
Access to undeclared static property App\Filament\Resources\CourseResource\Pages\CreateCourseLesson::$relationship
This is the content of my CourseResource\Pages\CreateCourseLesson.php
file.
<?php
namespace App\Filament\Resources\CourseResource\Pages;
use App\Filament\Resources\CourseResource;
use Guava\FilamentNestedResources\Concerns\NestedPage;
use Guava\FilamentNestedResources\Pages\CreateRelatedRecord;
class CreateCourseLesson extends CreateRelatedRecord
{
use NestedPage;
protected static string $resource = CourseResource::class;
}
Did I miss something here?
When creating lesson from the relation page.
1.0
8.3
11
macOS
No response
I am unable to get nested relationship working despite following the readme, as well as the example https://github.com/GuavaCZ/filament-nested-resources-demo
Here is a gist showing my resource config: https://gist.github.com/skills-up/95e0fb477bbe03972d5e4c46cb1fedb5
Generate the resource using command line.
Modify pages to include NestedPage trait.
Create additional pages with NestedPage and NestedRelationManager traits.
1.0.1
8.2.18
11.9.2
macOS
No response
When generating the name of a nested resource route, the route params not not removed.
Create a nested resource and run php artisan route:list
. Routes names will look like this filament.admin.resources.projects.{projectRecord?}.subcontractor-contracts.edit
instead of this filament.admin.resources.projects.subcontractor-contracts.edit
.
1.0.0-alpha.5
8.1.24
^10.10
macOS
No response
I see a 404 error when nesting resources with LongCamelCaseNames.
For example I have a model named ProjectSpNature (with the resource named ProjectSpNatureResource) and the generated route as per artisan route:list
is
admin/projects/{projectRecord?}/project-sp-natures/{project sp natureRecord?}/building-blocks/create
instead of
admin/projects/{projectRecord?}/project-sp-natures/{projectSpNatureRecord?}/building-blocks/create
This creates a 404 error probably because of the spaces inside the parameter
1.0.0-alpha.5
8.2.12
10.30.1
macOS
I think the solution could be changing the helper function that gets the route parameter
from
if (! function_exists('Guava\Filament\NestedResources\get_model_route_parameter')) {
function get_model_route_parameter(string | Model $model): string
{
return get_model_label(is_string($model) ? $model : $model::class) . 'Record';
}
}
to
if (! function_exists('Guava\Filament\NestedResources\get_model_route_parameter')) {
function get_model_route_parameter(string | Model $model): string
{
return Str::camel(get_model_label(is_string($model) ? $model : $model::class)) . 'Record';
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.