F
Filament13mo ago
Samir

Filament Custom Page always shows admin panel navigation

Filament Custom Page 'ListProductSellers' in my Buyer Panel always shows results with Admin panel sidebar navigation. My expectation is to show results with the Buyer Panel sidebar navigation. This page is not associated with any resource. I am defining its route in web.php.
Route::get('/buyer/{product}/{key}/sellers', ListProductSellers::class)->name('buyer.product.sellers');
Route::get('/buyer/{product}/{key}/sellers', ListProductSellers::class)->name('buyer.product.sellers');
In my ListProductSellers class, I have a table for an Eloquent relationship. I am calling this Custom Page from another livewire component blade file using a filament link.
<x-filament::link :href="route('buyer.product.sellers', ['product' => $product,'key' => $product->id])">
<span class="text-xs font-medium uppercase text-gray-500 dark:text-gray-500"> View Sellers</span>
</x-filament::link>
<x-filament::link :href="route('buyer.product.sellers', ['product' => $product,'key' => $product->id])">
<span class="text-xs font-medium uppercase text-gray-500 dark:text-gray-500"> View Sellers</span>
</x-filament::link>
I have attached my ListProductSeller class code. Please let me know where I am wrong.
Solution:
Bingo. I got it working. Debugging shows that whenever a Filament Custom Page gets called from anywhere as a URL, the URL parameters passed by the caller are not used for automatically Initialise using the mount('ID or entire Instance as parameter') method in the Filament Custom Page class. URL parameters are present in a Filament Custom Page as a Super Global Variable which can be assessed Using $_GET[‘one_of the_url_parameters’] // You can pass ID as a parameter. ...
Jump to solution
17 Replies
Dennis Koch
Dennis Koch13mo ago
This page is not associated with any resource. I am defining its route in web.php.
Why are you doing it like this?
Samir
SamirOP13mo ago
I could be wrong. I didn't associate this with any resources because I felt my Buyer panel does not have any resources currently. My Product and Seller resources are with the Admin panel. The buyer panel has a separate authentication guard. I don't know what is the right way to call this private page with query parameters as a link from other livewire components. I am fine not using the route in web.php.
Dennis Koch
Dennis Koch13mo ago
You don't need to add it to resources but you can still register is via the panel
Samir
SamirOP13mo ago
Please guide me how.
Dennis Koch
Dennis Koch13mo ago
If you created it for the Buyer Panel it should be in the Pages folder and auto registered if you have ->discoverPages() on your panel config.
Samir
SamirOP13mo ago
Yes it is present in filament->buyer->pages folder. I dont have any problem if i dont have any query parameter. It does not even ask route definition in web.php. But with query parameter, I get route definition error if I dont use route in web.php I have now deleted my route from web.php. Using the following link to access my Filament Custom Page.
<a href="{{ route('filament.buyer.pages.list-product-sellers', ['product_id' => $product->id]) }}">View Sellers</a>
<a href="{{ route('filament.buyer.pages.list-product-sellers', ['product_id' => $product->id]) }}">View Sellers</a>
But I am repeatedly getting folowing error: Illuminate\Contracts\Container\BindingResolutionException Unable to resolve dependency [Parameter #0 [ <required> $product_id ]] in class App\Filament\Buyer\Pages\ListProductSellers . I using follwoing mount method in ListProductSellers
public function mount($product_id): void
{
$this->product = Product::find($product_id);

}
public function mount($product_id): void
{
$this->product = Product::find($product_id);

}
Dennis Koch
Dennis Koch13mo ago
Does your slug match the argument name?
Samir
SamirOP13mo ago
I have not touched my slug. Itis default generated by Custom page.
Dennis Koch
Dennis Koch13mo ago
Yes, but you touched the mount() method. I think slug and mount must match
Samir
SamirOP13mo ago
You mean adding protected static ?string $slug = '{product_id}' in Custom page class. This gives error to me. Cannot assign null to property App\Filament\Buyer\Pages\ListProductSellers::$product of type App\Models\Product. This may be an error in Public Product $product assignment. How to match slug with mount. I am cluless hwo to proceed?
Dennis Koch
Dennis Koch13mo ago
Can you share the updated code?
Samir
SamirOP13mo ago
Attched My custom Page class. Follwing link I am using from another component blade file to access my custom page
<a href="{{ route('filament.buyer.pages.list-product-sellers', ['product_id' => $product->id]) }}">View Sellers</a>
<a href="{{ route('filament.buyer.pages.list-product-sellers', ['product_id' => $product->id]) }}">View Sellers</a>
Dennis Koch
Dennis Koch13mo ago
The error above says, that Product::find($product_id); is null. Did you check what $product_id is?
Samir
SamirOP13mo ago
I am clueless why Product::find($produt_id) returing null. I changed my mount a bit. Instead of passing $product_id, I am now passing $product. In the link route now looks like below:
<a href="{{ route('filament.buyer.pages.list-product-sellers', ['product' => $product]) }}">View Sellers</a>
<a href="{{ route('filament.buyer.pages.list-product-sellers', ['product' => $product]) }}">View Sellers</a>
. All my error is gone but I dont have any table data. It says no sellers where as I can clearly see I have a list. I have following url showling in broser. http://localhost/buyer/list-product-sellers?product=381 . You can see it is clearly having product ID 381. In my original issue using route in web.php I have everything right but with admin panel sidebar. This error null occurs only when I try to change the slug and assign as slug = {$id}. When slug is commented out, I am repeatedly getting folowing error when link uses product ID as parameter: Illuminate\Contracts\Container\BindingResolutionException Unable to resolve dependency [Parameter #0 [ <required> $product_id ]] in class App\Filament\Buyer\Pages\ListProductSellers . As mentioned when I change parameter from product_id to product and change my mount accordingly. Then error is gone but my page has not table result data.
Dennis Koch
Dennis Koch13mo ago
When slug is commented out, I am repeatedly getting folowing error when link uses product ID as parameter:
Which makes sense, as it cannot resolve that param from your url
As mentioned when I change parameter from product_id to product and change my mount accordingly. Then error is gone but my page has not table result data.
What's the content of $this->product and $this->product->mainsellers()? Did you debug this?
Samir
SamirOP12mo ago
I got this code running in a modal containing Livewire component code. No changes. Just implemented the Livewire component instead of the filament custom page. This component is triggered through Modal action. The custom page is receiving an empty mount. I don't know why. In fact, I am unable to implement any Filament custom pages which need a mount parameter.
Solution
Samir
Samir12mo ago
Bingo. I got it working. Debugging shows that whenever a Filament Custom Page gets called from anywhere as a URL, the URL parameters passed by the caller are not used for automatically Initialise using the mount('ID or entire Instance as parameter') method in the Filament Custom Page class. URL parameters are present in a Filament Custom Page as a Super Global Variable which can be assessed Using $_GET[‘one_of the_url_parameters’] // You can pass ID as a parameter. Do not create route in web.php for Filament Custom Pages if used for logged-in users. Initialise using mount() like below:
public Product $product;
public $productId;
public function mount(): void
{
$this->productId = $_GET['productID'];
$this->product = Product::find($this->productId);
}


//mount($productID) // does not work or initialise.
public Product $product;
public $productId;
public function mount(): void
{
$this->productId = $_GET['productID'];
$this->product = Product::find($this->productId);
}


//mount($productID) // does not work or initialise.
Sharing my entire code in the attachment. This is applicable anywhere wherever one wants to call the Custom Filament Page from a URL
Want results from more Discord servers?
Add your server