Daniel Reales
Daniel Reales
FFilament
Created by Daniel Reales on 5/19/2024 in #❓┊help
Listening for broadcast events multi-tenancy
Hi guys, I'm new to using broadcasting in Laravel and I'm testing Laravel Reverb. Right now, I have it working so that when a user registers an appointment, if another logged-in user is on the same team, their appointment panel is updated with the reservation. So far, so good. Each user has X associated stores. I actually need it so that if user A, who is associated with stores 1 and 2, registers an event, it updates user B who is also associated with stores 1 and 2. Currently, it only works if both users are in the same store, but if they are in different stores, it doesn't update. What am I doing wrong? This is my code: //chanels.php:
Broadcast::channel('stores.{storeId}', function (User $user, int $storeId) {
$userStores = $user->stores()->pluck('id')->toArray();

if (in_array($storeId, $userStores)) {
return ['id' => $user->id, 'name' => $user->name];
}
});
Broadcast::channel('stores.{storeId}', function (User $user, int $storeId) {
$userStores = $user->stores()->pluck('id')->toArray();

if (in_array($storeId, $userStores)) {
return ['id' => $user->id, 'name' => $user->name];
}
});
//RefreshAppointmentsEvent.php:
class RefreshAppointmentsEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(public Store $store)
{
//
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('stores.'.$this->store->id),
];
}
}
class RefreshAppointmentsEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(public Store $store)
{
//
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('stores.'.$this->store->id),
];
}
}
//script for loading events:
<script>
window.addEventListener('DOMContentLoaded', function () {
window.Echo.channel('stores.{{ Filament\Facades\Filament::getTenant()->id }}')
.listen('RefreshAppointmentsEvent', (event) => {
console.log('test')
Livewire.dispatch('refreshData');
});
});
</script>
<script>
window.addEventListener('DOMContentLoaded', function () {
window.Echo.channel('stores.{{ Filament\Facades\Filament::getTenant()->id }}')
.listen('RefreshAppointmentsEvent', (event) => {
console.log('test')
Livewire.dispatch('refreshData');
});
});
</script>
3 replies
FFilament
Created by Daniel Reales on 4/10/2024 in #❓┊help
Select default relationship
<?php

namespace App\Filament\User\Pages;

use App\Enums\PaymentType;
use App\Models\Store;
use Filament\Facades\Filament;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Pages\Dashboard as BaseDashboard;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;

class Dashboard extends BaseDashboard
{
use HasFiltersForm;

protected static ?string $navigationIcon = 'heroicon-o-home';
protected static ?string $title = 'Escritorio';
protected static string $view = 'filament-panels::pages.dashboard';

public function mount(): void
{
abort_unless(auth()->user()->hasRole('user'), 403);
}

public static function shouldRegisterNavigation(): bool
{
return auth()->user()->hasRole('user');
}

public function filtersForm(Form $form): Form
{
// dd(auth()->user()->stores()->pluck('name', 'id'));
return $form
->schema([
Select::make('stores')
->multiple()
->relationship('stores', 'name')
->searchable()
->preload()
->default([Filament::getTenant()->id])
->options(auth()->user()->stores()->pluck('name', 'id'))
->label('Tiendas'),
DatePicker::make('startDate')->default(now())->label('Desde'),
DatePicker::make('endDate')->default(now())->label('Hasta'),
Select::make('payment_method')->options(PaymentType::class)->label('Método de pago')
]);
}
}
<?php

namespace App\Filament\User\Pages;

use App\Enums\PaymentType;
use App\Models\Store;
use Filament\Facades\Filament;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Pages\Dashboard as BaseDashboard;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;

class Dashboard extends BaseDashboard
{
use HasFiltersForm;

protected static ?string $navigationIcon = 'heroicon-o-home';
protected static ?string $title = 'Escritorio';
protected static string $view = 'filament-panels::pages.dashboard';

public function mount(): void
{
abort_unless(auth()->user()->hasRole('user'), 403);
}

public static function shouldRegisterNavigation(): bool
{
return auth()->user()->hasRole('user');
}

public function filtersForm(Form $form): Form
{
// dd(auth()->user()->stores()->pluck('name', 'id'));
return $form
->schema([
Select::make('stores')
->multiple()
->relationship('stores', 'name')
->searchable()
->preload()
->default([Filament::getTenant()->id])
->options(auth()->user()->stores()->pluck('name', 'id'))
->label('Tiendas'),
DatePicker::make('startDate')->default(now())->label('Desde'),
DatePicker::make('endDate')->default(now())->label('Hasta'),
Select::make('payment_method')->options(PaymentType::class)->label('Método de pago')
]);
}
}
But in no Select field it sets the default value I want, except in startDate and endDate, which do have it by default. What could be happening?
8 replies
FFilament
Created by Daniel Reales on 2/18/2024 in #❓┊help
No refresh component
I have the following hook when starting the panel:
FilamentView::registerRenderHook(
'panels::body.end',
fn (): string => Blade::render('@livewire(\'cash-desk-closing.check-last-closing\')'),
);
FilamentView::registerRenderHook(
'panels::body.end',
fn (): string => Blade::render('@livewire(\'cash-desk-closing.check-last-closing\')'),
);
The modal opens and everything works correctly. In this modal, I have a form that also creates a record correctly, and I have two events, one to close the modal and another to call another component:
$this->dispatch('updateTicket');
$this->dispatch('close-modal', id: 'check-last-closing');
$this->dispatch('updateTicket');
$this->dispatch('close-modal', id: 'check-last-closing');
This call $this->dispatch('updateTicket'); does not work. In the component where I want this event to be called, I have the following:
protected $listeners = ['updateTicket' => '$refresh'];
protected $listeners = ['updateTicket' => '$refresh'];
` But it does nothing. In other parts of the application, I have the same functionality and it works correctly, but I do it through an action passing the Component $livewire, and from here, I emit the event. Why might this be happening to me?
2 replies
FFilament
Created by Daniel Reales on 1/17/2024 in #❓┊help
How to add a distinct of two fields to a Repeater?
I have an Employee selector and a product. I need to make these two fields distinct, that is, neither the name of the employee nor the product can be repeated. How could I do this?
2 replies
FFilament
Created by Daniel Reales on 12/1/2023 in #❓┊help
HasFiltersForms not found
I can't found on Filamentphp v3: use Filament\Pages\Dashboard\Concerns\HasFiltersForm; https://filamentphp.com/docs/3.x/panels/dashboard#filtering-widget-data
7 replies
FFilament
Created by Daniel Reales on 11/29/2023 in #❓┊help
Datepicker without time
Hi, I'm using this Datepicker:
DatePicker::make('created_from')
->native(false)
->displayFormat('d/m/Y')
->minDate(now()->subMonths(2))
->maxDate(now())
->label('Desde')
->default(now()),
DatePicker::make('created_from')
->native(false)
->displayFormat('d/m/Y')
->minDate(now()->subMonths(2))
->maxDate(now())
->label('Desde')
->default(now()),
With this I'm getting Date with format 'Y-m-d H:i:s' but I don't need time, so I try to do ->time(false) but it's not working. If I use ->native(true) it's works.
4 replies
FFilament
Created by Daniel Reales on 9/26/2023 in #❓┊help
How to create a requiredIf condition in a relationship?
I would like to do this: TextInput::make('price') ->requiredIf('store.type_tax', TaxType::Product->value) ->numeric() ->inputMode('decimal') ->step(0.01) ->label('Price') ->columnSpan(['md' => 6]), How can I retrieve the 'type_tax' from the 'store' relationship and make this field required based on that value?
2 replies
FFilament
Created by Daniel Reales on 9/19/2023 in #❓┊help
Error removing image from Custom Path Generator Media Library
I have this Custom Path Generator: class CustomPathGenerator implements BasePathGenerator { /* * Get the path for the given media, relative to the root storage path. */ public function getPath(Media $media): string { return match ($media->model_type) { Store::class => Store::PATH_IMAGES . '/' . Filament::getTenant()->id . '/' . $media->getKey() . '/', Catalogue::class => Catalogue::PATH_IMAGES . '/' . Filament::getTenant()->id . '/' . $media->getKey() . '/', Category::class => Category::PATH_IMAGES . '/' . Filament::getTenant()->id . '/' . $media->getKey() . '/', Subcategory::class => Subcategory::PATH_IMAGES . '/' . Filament::getTenant()->id . '/' . $media->getKey() . '/', default => $media->getKey() . '/', }; } /* * Get the path for conversions of the given media, relative to the root storage path. */ public function getPathForConversions(Media $media): string { return $this->getPath($media).'conversions/'; } /* * Get the path for responsive images of the given media, relative to the root storage path. */ public function getPathForResponsiveImages(Media $media): string { return $this->getPath($media).'responsive-images/'; } } It creates correctly the image but If I try to delete de image, not remove the image. Why?
2 replies
FFilament
Created by Daniel Reales on 9/14/2023 in #❓┊help
Send email after register user
No description
21 replies
FFilament
Created by Daniel Reales on 6/27/2023 in #❓┊help
Close Modal After Bulk Action
I have a confirmation modal for a custom bulk action. I neeed to close this modal when process is done. How I can do this?
27 replies
FFilament
Created by Daniel Reales on 6/10/2023 in #❓┊help
How to show in a column from table sum from relationship
I have this: Tables\Columns\TextColumn::make('order_items_sum_price') ->sum('orderItems', 'price')->money('eur')->sortable()->label('Precio Total') But every orderItem has a column with amount. I need to multiply the quantity by its price and in turn make the total sum. How could I do it?
6 replies