Povilas K
Povilas K
FFilament
Created by Akram on 5/27/2024 in #❓┊help
Hi guys 👋I want to make cascade drop down list from database or api dynamicaly in filamentphp
No description
4 replies
FFilament
Created by Akram on 5/27/2024 in #❓┊help
Hi guys 👋I want to make cascade drop down list from database or api dynamicaly in filamentphp
If you meant parent-child dropdowns, here's one of my examples:
Forms\Components\Select::make('country_id')
->live()
->label('Country')
->dehydrated(false)
->options(Country::pluck('name', 'id')),
Forms\Components\Select::make('city_id')
->required()
->label('City')
->placeholder(fn (Forms\Get $get): string => empty($get('country_id')) ? 'First select country' : 'Select an option')
->options(function (Forms\Get $get): Collection {
return City::where('country_id', $get('country_id'))->pluck('name', 'id');
}),
Forms\Components\Select::make('country_id')
->live()
->label('Country')
->dehydrated(false)
->options(Country::pluck('name', 'id')),
Forms\Components\Select::make('city_id')
->required()
->label('City')
->placeholder(fn (Forms\Get $get): string => empty($get('country_id')) ? 'First select country' : 'Select an option')
->options(function (Forms\Get $get): Collection {
return City::where('country_id', $get('country_id'))->pluck('name', 'id');
}),
4 replies
FFilament
Created by IamJohnDev on 5/21/2024 in #❓┊help
Set the Time Array to Option Select
You can maybe compare output format or logic
7 replies
FFilament
Created by IamJohnDev on 5/21/2024 in #❓┊help
Set the Time Array to Option Select
Not sure if that's the same example but we had a similar project with radio timeslots in one of our tutorials, here's the code
public static function form(Form $form): Form
{
$dateFormat = 'Y-m-d';

return $form
->schema([
DatePicker::make('date')
->native(false)
->minDate(now()->format($dateFormat))
->maxDate(now()->addWeeks(2)->format($dateFormat))
->format($dateFormat)
->required()
->live(),
Radio::make('track')
->options(fn (Get $get) => self::getAvailableReservations($get))
->hidden(fn (Get $get) => ! $get('date'))
->required()
->columnSpan(2),
]);
}

public static function getAvailableReservations(Get $get): array
{
$date = Carbon::parse($get('date'));
$startPeriod = $date->copy()->hour(14);
$endPeriod = $date->copy()->hour(16);
$times = CarbonPeriod::create($startPeriod, '1 hour', $endPeriod);
$availableReservations = [];

$tracks = Track::with([
'reservations' => function ($q) use ($startPeriod, $endPeriod) {
$q->whereBetween('start_time', [$startPeriod, $endPeriod]);
},
])
->get();

foreach ($tracks as $track) {
$reservations = $track->reservations->pluck('start_time')->toArray();

$availableTimes = $times->copy()->filter(function ($time) use ($reservations) {
return ! in_array($time, $reservations) && ! $time->isPast();
})->toArray();

foreach ($availableTimes as $time) {
$key = $track->id . '-' . $time->format('H');
$availableReservations[$key] = $track->title . ' ' . $time->format('H:i');
}
}

return $availableReservations;
}
public static function form(Form $form): Form
{
$dateFormat = 'Y-m-d';

return $form
->schema([
DatePicker::make('date')
->native(false)
->minDate(now()->format($dateFormat))
->maxDate(now()->addWeeks(2)->format($dateFormat))
->format($dateFormat)
->required()
->live(),
Radio::make('track')
->options(fn (Get $get) => self::getAvailableReservations($get))
->hidden(fn (Get $get) => ! $get('date'))
->required()
->columnSpan(2),
]);
}

public static function getAvailableReservations(Get $get): array
{
$date = Carbon::parse($get('date'));
$startPeriod = $date->copy()->hour(14);
$endPeriod = $date->copy()->hour(16);
$times = CarbonPeriod::create($startPeriod, '1 hour', $endPeriod);
$availableReservations = [];

$tracks = Track::with([
'reservations' => function ($q) use ($startPeriod, $endPeriod) {
$q->whereBetween('start_time', [$startPeriod, $endPeriod]);
},
])
->get();

foreach ($tracks as $track) {
$reservations = $track->reservations->pluck('start_time')->toArray();

$availableTimes = $times->copy()->filter(function ($time) use ($reservations) {
return ! in_array($time, $reservations) && ! $time->isPast();
})->toArray();

foreach ($availableTimes as $time) {
$key = $track->id . '-' . $time->format('H');
$availableReservations[$key] = $track->title . ' ' . $time->format('H:i');
}
}

return $availableReservations;
}
7 replies
FFilament
Created by code jam on 5/20/2024 in #❓┊help
multiple panels on single dashboard as tabs?
@Desmond Njuguna mmm, that's news to me. Adding that plugin for a review on YouTube, thanks 🙂
9 replies
FFilament
Created by JustMe on 5/19/2024 in #❓┊help
Changing registration form
For customizing registration, you would need to build your Registration class, like here: https://filamentphp.com/docs/3.x/panels/users#customizing-the-authentication-features Our tutorial about adding extra field: https://laraveldaily.com/post/filament-registration-form-extra-fields-choose-user-role But you can add more fields, and/or you can build a Wizard inside that class, too, with your second step. For checking the fields on every action, you would need to build a Laravel Middleware, and then apply it on the panel here: https://filamentphp.com/docs/3.x/panels/configuration#applying-middleware-to-authenticated-routes
4 replies
FFilament
Created by hrvzmndz on 5/20/2024 in #❓┊help
Bootstrap for Landing Page?
Filament is based on Tailwind and it is not compatible with Bootstrap in any other way. So you can have your existing project with Bootstrap, and then link so the adminpanel /admin which would be Filament. So, two separate projects.
3 replies
FFilament
Created by code jam on 5/20/2024 in #❓┊help
multiple panels on single dashboard as tabs?
I don't think it's possible, as each panel in Filament requires its own settings, URL, etc. Unless you're talking about non-Filament outside app which would show those links as tabs with checking permissions, and then inside you would have those three tabs. Or a separate ovrerarching Filament installation on some subdomain that would lead to those three separate links on another subdomain
9 replies
FFilament
Created by zenepay on 5/20/2024 in #❓┊help
I try to seed using has function for relationship but does not create child record.
I would raise another question: why you need house_no in both parent and child records? The relationship should be probably by property_services.property_id with hasMany. And if you do need that house_no in the property_services, you can call it by relationship: property_service.property.house_no
7 replies
FFilament
Created by mrvn on 5/20/2024 in #❓┊help
Customize VerifyEmail template and other login related emails
Not sure about Verification email specifically, though, haven't tried, but maybe the same logic would work
10 replies
FFilament
Created by mrvn on 5/20/2024 in #❓┊help
Customize VerifyEmail template and other login related emails
10 replies
FFilament
Created by Rad on 5/6/2024 in #❓┊help
Custom Database Notification Model
@Rad not sure if I'm not too late, but we experimented and came up with this solution. Create your own class extending BaseNotification, then bind it in the provider, and then use it where needed. app/Filament/Notification.php:
namespace App\Filament;

use Closure;
use Illuminate\Support\Arr;
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Actions\ActionGroup;
use Filament\Notifications\Notification as BaseNotification;

class Notification extends BaseNotification
{
/**
* @param array<Action | ActionGroup> | ActionGroup | Closure $actions
*/
public function actions(array | ActionGroup | Closure $actions): static
{
$this->actions = Arr::prepend(
$actions,
Action::make('goToDashboard')
->label('Go to Dashboard')
->url(fn() => route('filament.admin.pages.dashboard'))
);

return $this;
}
}
namespace App\Filament;

use Closure;
use Illuminate\Support\Arr;
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Actions\ActionGroup;
use Filament\Notifications\Notification as BaseNotification;

class Notification extends BaseNotification
{
/**
* @param array<Action | ActionGroup> | ActionGroup | Closure $actions
*/
public function actions(array | ActionGroup | Closure $actions): static
{
$this->actions = Arr::prepend(
$actions,
Action::make('goToDashboard')
->label('Go to Dashboard')
->url(fn() => route('filament.admin.pages.dashboard'))
);

return $this;
}
}
app/Providers/AppServiceProvider.php:
use App\Filament\Notification;
use Filament\Notifications\Notification as BaseNotification;

public function register(): void
{
$this->app->bind(BaseNotification::class, Notification::class);
}
use App\Filament\Notification;
use Filament\Notifications\Notification as BaseNotification;

public function register(): void
{
$this->app->bind(BaseNotification::class, Notification::class);
}
Then, in the Create pages or wherever you need, call your Notification class: app/Filament/Resources/PostResource/Pages/CreatePost.php:
use App\Filament\Notification;

// ...

public function afterCreate(): void
{
Notification::make()
->title('Post created')
->sendToDatabase(auth()->user());
}
use App\Filament\Notification;

// ...

public function afterCreate(): void
{
Notification::make()
->title('Post created')
->sendToDatabase(auth()->user());
}
4 replies
FFilament
Created by MZX on 5/8/2024 in #❓┊help
How do I hide panels based on the User who is logged in? Its for a school management system.
@MZX so yeah, it means you're working within the same panel, then it's a simple version of just using Laravel Policies as the link stated earlier. Or another example specifically for Deleting records: https://filamentphp.com/docs/3.x/panels/resources/deleting-records#authorization
10 replies
FFilament
Created by 阿信 on 5/8/2024 in #❓┊help
Access Control for the Resource?
Users may access the Edit page if the update() method of the model policy returns true. https://filamentphp.com/docs/3.x/panels/resources/editing-records#authorization
5 replies
FFilament
Created by 阿信 on 5/8/2024 in #❓┊help
Access Control for the Resource?
5 replies
FFilament
Created by MZX on 5/8/2024 in #❓┊help
How do I hide panels based on the User who is logged in? Its for a school management system.
@MZX it would be easier to help if you specify the actual example of what do you mean by "some panels will be hidden from them", which panels/resources etc. Because the solution may be pretty individual depending on scenario: restrict panels? use policies? tenancy? etc
10 replies
FFilament
Created by Jigar D on 5/6/2024 in #❓┊help
In registration page, have dynamic steps for Wizard based of step's afterValidation
@Jigar D very elegantly solved, congrats! With security risk, yes it's implied with the logic that you chose for this. Another approach would be to send invites personally for registration from that specific company domain. And more approaches exist, I'm sure.
7 replies
FFilament
Created by pgferro on 5/3/2024 in #❓┊help
Custom BulkAction
Update: we published a snippet on our examples page, but to avoid being too "promotional", here's the main code:
use Barryvdh\DomPDF\Facade\Pdf;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Blade;

public static function table(Table $table): Table
{
return $table
// ...
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\BulkAction::make('Export')
->icon('heroicon-m-arrow-down-tray')
->openUrlInNewTab()
->deselectRecordsAfterCompletion()
->action(function (Collection $records) {
return response()->streamDownload(function () use ($records) {
echo Pdf::loadHTML(
Blade::render('pdf', ['records' => $records])
)->stream();
}, 'users.pdf');
}),
]),
]);
}
use Barryvdh\DomPDF\Facade\Pdf;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Blade;

public static function table(Table $table): Table
{
return $table
// ...
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\BulkAction::make('Export')
->icon('heroicon-m-arrow-down-tray')
->openUrlInNewTab()
->deselectRecordsAfterCompletion()
->action(function (Collection $records) {
return response()->streamDownload(function () use ($records) {
echo Pdf::loadHTML(
Blade::render('pdf', ['records' => $records])
)->stream();
}, 'users.pdf');
}),
]),
]);
}
13 replies
FFilament
Created by Pekempy on 5/6/2024 in #❓┊help
(Beginner question) Repeater - Formatting the output after update
But also, it depends on how exactly do you save that json in the table
14 replies