error when edit or create on some resources

Hi, I have this problem at edit and create works fine, after refresh this apears on create and edit works fine, after each refresh it changes. In console apears the error: XHR POST .... app.filament.resources.page-resource.pages.manage-pages [HTTP/2 500 Internal Server Error 702ms]. It's only on some resources, rest of them work fine. Could you help me, pls?
22 Replies
Dennis Koch
Dennis Koch2y ago
Not sure why you are shown a 503 when there is a 500 in the XHR. Can you check the DevTools network tab or Laravel log and see what’s the error is?
Jessy
JessyOP2y ago
when create appears [HTTP/2 503 Service Unavailable 670ms], when edit is: [HTTP/2 500 Internal Server Error 616ms]
Dennis Koch
Dennis Koch2y ago
For 500: what’s the actual error? It’s either returned with the XHR request or should be in the Laravel log
Jessy
JessyOP2y ago
XHR POST ...app.filament.resources.page-resource.pages.manage-pages [HTTP/2 500 Internal Server Error 839ms]
Dennis Koch
Dennis Koch2y ago
Can you please show the result of the request in the network tab of DevTools? If any of this I unclear, please ask.
Jessy
JessyOP2y ago
status 500, method POST, file app.filament.resources.page-resource.pages.manage-pages, initiator livewire.js:13(fetch), type: html. this? in log is this error: local.ERROR: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2621440 bytes) {"userId":2,"exception":"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0):...
Dennis Koch
Dennis Koch2y ago
No. The result that’s coming back. The payload. That sounds like a loop. Can you share the code if the resource?
Jessy
JessyOP2y ago
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('title')
->maxLength(255),
Forms\Components\TextInput::make('url')
->maxLength(255),
Forms\Components\RichEditor::make('html')
->maxLength(65535)
->columnSpan('full'),
Forms\Components\Select::make('status')
->options(
Dictionary::where('code', 'status')
->first()
->details
->pluck('name', 'id')
),
Forms\Components\Select::make('page_type')
->options(
Dictionary::where('code', 'page_type')
->first()
->details
->pluck('name', 'id')
),
Forms\Components\Select::make('category_id')
->options(
Category::all()->pluck('name', 'id')
),
Forms\Components\FileUpload::make('page_image')
->image()
->preserveFilenames()
->directory('upload/pages/images'),
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('title')
->maxLength(255),
Forms\Components\TextInput::make('url')
->maxLength(255),
Forms\Components\RichEditor::make('html')
->maxLength(65535)
->columnSpan('full'),
Forms\Components\Select::make('status')
->options(
Dictionary::where('code', 'status')
->first()
->details
->pluck('name', 'id')
),
Forms\Components\Select::make('page_type')
->options(
Dictionary::where('code', 'page_type')
->first()
->details
->pluck('name', 'id')
),
Forms\Components\Select::make('category_id')
->options(
Category::all()->pluck('name', 'id')
),
Forms\Components\FileUpload::make('page_image')
->image()
->preserveFilenames()
->directory('upload/pages/images'),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('id')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('title')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('getStatus.name')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('url')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('getPageType.name')
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('category.name')
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('created_at')
->datetime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->datetime()
->sortable()
->searchable(),
])
->defaultSort( column: 'id', direction: 'desc')
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('id')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('title')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('getStatus.name')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('url')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('getPageType.name')
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('category.name')
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('created_at')
->datetime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->datetime()
->sortable()
->searchable(),
])
->defaultSort( column: 'id', direction: 'desc')
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
]);
}
public static function getPages(): array
{
return [
'index' => Pages\ManagePages::route('/'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\ManagePages::route('/'),
];
}
just the form and the table
Dennis Koch
Dennis Koch2y ago
I guess it’s related to the 2 selects. Can you remove them and try again?
Jessy
JessyOP2y ago
ok, now the create modal works but I still have 500 error on edit
Dennis Koch
Dennis Koch2y ago
Still the same error?
Jessy
JessyOP2y ago
yes, and now changes: if I refresh the page the error in on create and edit works
Dennis Koch
Dennis Koch2y ago
So removed all Selects and still get "out of memory" errors?
Jessy
JessyOP2y ago
yes
Dennis Koch
Dennis Koch2y ago
Anything special with the Model for that form? Can you share the code?
Jessy
JessyOP2y ago
private function doShortcodes($content)
{
return preg_replace_callback('/{[a-zA-Z-]*}/m', function ($match) {
$products = Product::where('category_id', $this->category_id);
switch($match[0]) {
case '{top-cheap}':
$products->orderBy('price', 'asc');
$products->take(6);
$products = $products->get();
return view('components.lw', ['view' => 'components.top-shortcode', 'data' => ['top' => $products]]);
break;

case '{top-good}':
$products->orderBy('price', 'desc');
$products->take(6);
$products = $products->get();
return view('components.lw', ['view' => 'components.top-shortcode', 'data' => ['top' => $products]]);
break;

case '{top-discount}':
$products->orderByRaw('(old_price - price) desc');
$products->take(6);
$products = $products->get();
return view('components.lw', ['view' => 'components.top-shortcode', 'data' => ['top' => $products]]);
break;

case '{top-voted}':
$products->orderBy('rating', 'desc');
$products->take(6);
$products = $products->get();
return view('components.lw', ['view' => 'components.top-shortcode', 'data' => ['top' => $products ]]);
break;
private function doShortcodes($content)
{
return preg_replace_callback('/{[a-zA-Z-]*}/m', function ($match) {
$products = Product::where('category_id', $this->category_id);
switch($match[0]) {
case '{top-cheap}':
$products->orderBy('price', 'asc');
$products->take(6);
$products = $products->get();
return view('components.lw', ['view' => 'components.top-shortcode', 'data' => ['top' => $products]]);
break;

case '{top-good}':
$products->orderBy('price', 'desc');
$products->take(6);
$products = $products->get();
return view('components.lw', ['view' => 'components.top-shortcode', 'data' => ['top' => $products]]);
break;

case '{top-discount}':
$products->orderByRaw('(old_price - price) desc');
$products->take(6);
$products = $products->get();
return view('components.lw', ['view' => 'components.top-shortcode', 'data' => ['top' => $products]]);
break;

case '{top-voted}':
$products->orderBy('rating', 'desc');
$products->take(6);
$products = $products->get();
return view('components.lw', ['view' => 'components.top-shortcode', 'data' => ['top' => $products ]]);
break;
case '{top-popular}':
$productClicked = Product::leftJoin('product_alternatives', 'products.id', '=', 'product_alternatives.product_id')
->leftJoin('product_alternative_clicks', 'product_alternatives.id', '=', 'product_alternative_clicks.alternative_id')
->select('products.id', 'products.price')
->selectRaw('count(product_alternative_clicks.id) as total')
->where('category_id', $this->category_id)
->groupBy('products.id', 'products.price')
->orderByDesc('total')
->having('total', '>', 0)
->take(6)
->get()
->toArray();
$productsId = array_column($productClicked, 'id');
$products->whereIn('id', $productsId);
$products->orderBy('id', 'desc');
$products->take(6);
$products = $products->get();
return view('components.lw', ['view' => 'components.top-shortcode', 'data' => ['top' => $products]]);
break;

case '{CONTACT-FORM}':
return view('components.lw', ['view' => 'form.contact-form', 'data' => ['title' => '1']]);
break;

default:
return $match[0];
break;
}
}, $content);
}
case '{top-popular}':
$productClicked = Product::leftJoin('product_alternatives', 'products.id', '=', 'product_alternatives.product_id')
->leftJoin('product_alternative_clicks', 'product_alternatives.id', '=', 'product_alternative_clicks.alternative_id')
->select('products.id', 'products.price')
->selectRaw('count(product_alternative_clicks.id) as total')
->where('category_id', $this->category_id)
->groupBy('products.id', 'products.price')
->orderByDesc('total')
->having('total', '>', 0)
->take(6)
->get()
->toArray();
$productsId = array_column($productClicked, 'id');
$products->whereIn('id', $productsId);
$products->orderBy('id', 'desc');
$products->take(6);
$products = $products->get();
return view('components.lw', ['view' => 'components.top-shortcode', 'data' => ['top' => $products]]);
break;

case '{CONTACT-FORM}':
return view('components.lw', ['view' => 'form.contact-form', 'data' => ['title' => '1']]);
break;

default:
return $match[0];
break;
}
}, $content);
}
yes, this function maybe it's because of this
Dennis Koch
Dennis Koch2y ago
When is this executed? Try removing it. Can you load one or multiple instances of the model without Filament?
Jessy
JessyOP2y ago
I removed the function, but I still have the error, without selects and without this function in console is also a warning: Error while fetching an original source: can't assign to property "metadata" on "unsupported protocol for sourcemap request webpack://filament/%3Cno%20source%3E": not an object Source URL: <unknown>
Dennis Koch
Dennis Koch2y ago
That’s currently unrelated. Focus on the PHP error
Jessy
JessyOP2y ago
If I remove RichEditor from PageResource , I don't have the error anymore. What my app don't like at RichEditor? And in the other 2 resources I removed the Repeater and now no errors. And also no Repeater and no RichEditor, and I need them
Dennis Koch
Dennis Koch2y ago
I don’t think it’s an issue with the components. Maybe with the model and the loaded data. It’s hard to debug a memory issue via Discord
Jessy
JessyOP2y ago
I don't think so either. I know these components work well. I removed them just to see if the error goes away. I will check the data loaded in the components. Thank you for your help!
Want results from more Discord servers?
Add your server