Custom button for a form

Hi, I created a custom button to create records in another way, the problem is that people who are not logged in can enter this path, how can I hide this path for people who are not logged in?
public static function getPages(): array
{
return [
'index' => Pages\ListAcademicComponents::route('/'),
'createform' => Pages\FormAcademicComponent::route('/form'),
//'create' => Pages\CreateAcademicComponent::route('/create'),
//'edit' => Pages\EditAcademicComponent::route('/{record}/edit'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListAcademicComponents::route('/'),
'createform' => Pages\FormAcademicComponent::route('/form'),
//'create' => Pages\CreateAcademicComponent::route('/create'),
//'edit' => Pages\EditAcademicComponent::route('/{record}/edit'),
];
}
No description
Solution:
But the route you showed is /form-academic-component not /dashboard/academic-components ?!
Jump to solution
17 Replies
Dennis Koch
Dennis Koch3mo ago
that people who are not logged in can enter this path
Filament shouldn't allow access without a login by default.
aacarrion4
aacarrion43mo ago
Yes, the problem is that I define the path in web for the redirection to work.
<?php
use App\Filament\Resources\AcademicComponentResource\Pages\FormAcademicComponent;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ReportGradeController;


Route::get('/form-academic-component', FormAcademicComponent::class)->name('form.academic.component');`
<?php
use App\Filament\Resources\AcademicComponentResource\Pages\FormAcademicComponent;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ReportGradeController;


Route::get('/form-academic-component', FormAcademicComponent::class)->name('form.academic.component');`
Dennis Koch
Dennis Koch3mo ago
There's your answers. If you register a separate path without authentication, then you don't get authentication. Why do you need that for redirection? Just use the URL to the page? Something like AcademicComponentResource::getUrl('createform')
aacarrion4
aacarrion43mo ago
Excuse me, where should I place this code?
Dennis Koch
Dennis Koch3mo ago
Where your redirect is
aacarrion4
aacarrion43mo ago
Forgive my ignorance, but from the resource FormAcademicComponent I am calling a custom view (filament.resources.academic-component-resource.pages.form-academic-component) for a save button, the problem is that I don't know where to define this path.
public static function getPages(): array
{
return [
'index' => Pages\ListAcademicComponents::route('/'),
'createform' => Pages\FormAcademicComponent::route('/createform'),
'create' => Pages\CreateAcademicComponent::route('/create'),
//'edit' => Pages\EditAcademicComponent::route('/{record}/edit'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListAcademicComponents::route('/'),
'createform' => Pages\FormAcademicComponent::route('/createform'),
'create' => Pages\CreateAcademicComponent::route('/create'),
//'edit' => Pages\EditAcademicComponent::route('/{record}/edit'),
];
}
FormAcademicComponent
<?php

namespace App\Filament\Resources\AcademicComponentResource\Pages;

use App\Filament\Resources\AcademicComponentResource;
use App\Models\AcademicComponent;
use Filament\Resources\Pages\CreateRecord;

class FormAcademicComponent extends CreateRecord
{
protected static string $resource = AcademicComponentResource::class;


protected static string $view = 'filament.resources.academic-component-resource.pages.form-academic-component';

public function form(Form $form): Form
{
return $form->schema([]);
}

public function save()
{
return redirect()->to('dashboard/academic-components');
}
}
<?php

namespace App\Filament\Resources\AcademicComponentResource\Pages;

use App\Filament\Resources\AcademicComponentResource;
use App\Models\AcademicComponent;
use Filament\Resources\Pages\CreateRecord;

class FormAcademicComponent extends CreateRecord
{
protected static string $resource = AcademicComponentResource::class;


protected static string $view = 'filament.resources.academic-component-resource.pages.form-academic-component';

public function form(Form $form): Form
{
return $form->schema([]);
}

public function save()
{
return redirect()->to('dashboard/academic-components');
}
}
filament.resources.academic-component-resource.pages.form-academic-component:
<x-filament-panels::page>
<form method="post" wire:submit="save">
{{ $this->form }}
<button type="submit" class="mt-4 px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">
Guardar
</button>
<button onclick="window.location.href='{{ url()->previous() }}';"
class="mt-4 px-4 py-2 bg-red-500 text-white rounded hover:bg-red-600">
Cancelar
</button>
</form>
</x-filament-panels::page>
<x-filament-panels::page>
<form method="post" wire:submit="save">
{{ $this->form }}
<button type="submit" class="mt-4 px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">
Guardar
</button>
<button onclick="window.location.href='{{ url()->previous() }}';"
class="mt-4 px-4 py-2 bg-red-500 text-white rounded hover:bg-red-600">
Cancelar
</button>
</form>
</x-filament-panels::page>
Dennis Koch
Dennis Koch3mo ago
Where do you use that public route /form-academic-component?
aacarrion4
aacarrion43mo ago
It's right in the resources folder
No description
aacarrion4
aacarrion43mo ago
And it is used to call the FormAcademicComponent.
public static function getPages(): array
{
return [
'index' => Pages\ListAcademicComponents::route('/'),
'createform' => Pages\FormAcademicComponent::route('/createform'),
'create' => Pages\CreateAcademicComponent::route('/create'),
//'edit' => Pages\EditAcademicComponent::route('/{record}/edit'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListAcademicComponents::route('/'),
'createform' => Pages\FormAcademicComponent::route('/createform'),
'create' => Pages\CreateAcademicComponent::route('/create'),
//'edit' => Pages\EditAcademicComponent::route('/{record}/edit'),
];
}
Dennis Koch
Dennis Koch3mo ago
I am talking about the route you registered. Not any view files. Where do you use that route? You said, you registered the route "to make redirection work". Where do you need this?
aacarrion4
aacarrion43mo ago
Ahh ok, I use it in the save method for the save button.
Dennis Koch
Dennis Koch3mo ago
This one? That's a different route though?
public function save()
{
return redirect()->to('dashboard/academic-components');
}
public function save()
{
return redirect()->to('dashboard/academic-components');
}
aacarrion4
aacarrion43mo ago
Yes, that's where I use it
Solution
Dennis Koch
Dennis Koch3mo ago
But the route you showed is /form-academic-component not /dashboard/academic-components ?!
Want results from more Discord servers?
Add your server