help
I have three tablets in the data base
User, admin, and company employee
I want to build a filament exclusively for the company's employees
The log account means that the only person entering the dashboard is a company employee
I tried to use Filament, but the account was registered in the user table
17 Replies
I tried to use Filament, but the account was registered in the user tableYes. That's just the default user:generate command. You can use any auth though. You can overwrite the auth guard that Filament uses via
->authGuard()
on the PanelProvider. Just use the guard that only allows company employees.class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login()
->colors([
'primary' => Color::Amber,
])
->discoverResources(in: app_path('Filament/Resources'), for: 'App\Filament\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\Filament\Pages')
->pages([
Pages\Dashboard::class,
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\Filament\Widgets')
->widgets([
Widgets\AccountWidget::class,
Widgets\FilamentInfoWidget::class,
])
->middleware([
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
AuthenticateSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class,
])
->authMiddleware([
Authenticate::class,
]);
}
}
in this code where can i edit to accept only company_employee for login
You can create an auth guard in Laravel (https://laravel.com/docs/master/authentication#adding-custom-guards) and pass this via
->authGuard()
(https://filamentphp.com/docs/3.x/panels/users#setting-the-authentication-guard)Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
Usually you would just define an auth guard via
config/auth.php
i create already guard how can i put it in filament to access only company_employee
Example:
->authGuard('your_guard')
on the Panelclass AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('company')
->login()
->colors([
'primary' => Color::Amber,
])
->discoverResources(in: app_path('Filament/Resources'), for: 'App\Filament\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\Filament\Pages')
->pages([
Pages\Dashboard::class,
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\Filament\Widgets')
->widgets([
Widgets\AccountWidget::class,
Widgets\FilamentInfoWidget::class,
])
->middleware([
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
AuthenticateSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class,
])
->authMiddleware([
Authenticate::class,
])->authGuard('employees');
}
}
i put this code
the error is BadMethodCallException
PHP 8.1.10
10.48.12
Method Illuminate\Auth\RequestGuard::attempt does not exist.
Bad Method Call
Did you mean Illuminate\Auth\RequestGuard::validate() ?
Please use code formatting as explained in #✅┊rules
Is
employees
an actual guard? Can you show config/auth.php
this all guards for my project
this all providers
i saw new error
in employee table i have this columns
and my code for login is in third image
how can i connect my login function with login page in filament
and the page not retuns to login page
The column is not found.
i want customize my table in the filament
You can extend the Login page and set your new page via
->login()
inside the panel provider.
Not sure whether sanctum works. I guess it should be session for filament.hello
i have this resource in message.txt
in createproduct file i have this code <?php
namespace App\Filament\Resources\ProductResource\Pages;
use App\Filament\Resources\ProductResource;
use App\Models\Product;
use App\Models\ProductUnit;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class CreateProduct extends CreateRecord
{
protected static string $resource = ProductResource::class;
protected function handleRecordCreation(array $data): Product
{
return DB::transaction(function () use ($data) {
$product = Product::create($data);
if (isset($data['units'])) {
foreach ($data['units'] as $unitData)
{
ProductUnit::create([
'product_id' => $product->id,
'unit_id' => $unitData['unit_id'],
'price' => $product['price'],
]);
}
}
return $product;
});
}
}
when i create units and prices for new product i saw this error SQLSTATE[HY000]: General error: 1364 Field 'price' doesn't have a default value
how can i fix it to create many unites and prices for product
the relationship between products and units is manyto many
@Aya Alghadban Is this related to the original issue? Please use one thread per question and use code formatting as mentioned in #✅┊rules