Tuto's Laravel Corner

TLC

Tuto's Laravel Corner

Join the community to ask questions about Tuto's Laravel Corner and get answers from other members.

Join

๐Ÿš€laravel

๐Ÿ’กfilament

V2 plugin create for V3

I try to replicate solution forest filament tab layout plugin for V3 but it give error at canbehidden trait
Solution:
i just drop the plugin and use another plugin !

Google Distance Matrix API

Hello, has anyone have experience with implementing the Google Distance Matrix API into a Filament form? I need to find a solution to calculate a distance between two addresses and I need to know the distance to every country border on the route. Does anyone can help me with some coding solutions?...

Multi-tenancy for a filament page

Hi there. I have an app with multi-tenancy and it is working well with all the resources in such panel. For one resource, I had to create a new filament page (not associated with the resource) to do some simple mathematical operations. Sum of total columns and division to calculate percentages. this works great as well. The issue I have is that I cant filter the calculations by tenant. It just add all the values in the table . Can someone provide any advise please?
Solution:
Well, if I understood correctly, you needed to do a total calculation somewhere in your app and that is why I suggested the way to complete the total calculations, but yes, for multi tenancy you would need to filter your registered users model with the where condition: $total_users_count = Users::where('type', 'admin'); (of course you will change it to your own where clause as per the project needs as I am not aware of that so I gave just an example to look for an admin, but can be of course something else ๐Ÿ˜‰ )...

Show multiple table columns in a single table column of ressource

Hey guys, me again. I am trying to find some documentation/info about how can I show in a table column the joined data from two fields (e.g. start_date and start_time which are two separate inputs of date/time would like to become: 21/12/2023 - 16:15 instead of showing each column separately. I believe we've done that with the pet clinic, but since I've started the project from video 1, I might have lost or not yet reached some of the merged data practice. Any hint or a link where to look as I seem to have some weird difficulty finding data in the documentation but I am not sure it is the fault of the DEVs who wrote the data...

Edit Create resource title text

Hey guys, Sorry if it sounds silly, but while working on my project, I've noticed that the text on every new resource adding is Create ... My question is what is the proper way to rename the text? ...
Solution:
Have you tried mofiying these two properties on the CreateTerminationFailure page?
protected static ?string $breadcrumb = 'Add Termination Failure';
protected static ?string $title = 'Add Termination Failure';
protected static ?string $breadcrumb = 'Add Termination Failure';
protected static ?string $title = 'Add Termination Failure';
...
No description

I'm having following error :ENUM

After defining the 'status' attribute in the 'AppointmentResource' and using 'App\Enums\AppointmentStatus,' I have added 'protected $casts = ['status' => AppointmentStatus::class]' in the model. However, I am encountering an error that says, 'Class "App\Enums\AppointmentStatus" not found.' I'm currently stuck at this point.
Solution:
it should look like this ```php <?php namespace App\Enums;...

Show record index in table row

Hey guys, I know this might sound a bit silly but I was reading the documentation of Filament and seem to not get my head around how can I show a simple table rows index instead of record id. Why I need that? Sometimes when we edit records and re-add some new, the ID of the table changes (of course) but we would still like to present the first one as 1, second as 2 etc. I am sure I am missing something ridiculously simple but just to speed up the custom project development and ask the great knowledge here to share some more, I will wait patiently for the answer to laugh at my miss (again) ๐Ÿ™‚...

Hello Tuto,

I'm having the following error. When I'm using tenancy stuff and trying to use them together EditProfile is not possible because have a route problem. Thank you for your help, I think more people can have this same problem....
No description

How to use custom Admin UI with Filament

Hello guys. II've been with Laravel for a year or so and I love it so far. So is with Livewire which surprised me with it's simplicity in many occasions in terms of dynamics and code easiness to digest. I've came across Filament in a few months so I am still learning my way through this incredible ecosystem but I feel comfortable now thanks to tuto and many other contributors to build a semi-complex project on my own. The one thing that I would like to know and I've done some research on it already is how can we build a fully customized admin theme still using Filament under the hood. And by fully customized theme I am not meaning to change colors, backgrounds, icons etc. that Filament already allow with the custom theme, but what I mean is to use the incredible power to build quickly with Filament but use a custom ADMIN UI like AdminLTE, CoreUI or any other admin design that a project requires us to use....
Solution:
Another alternative I was reading about was to have custom PAGES which we can design and if allowed to use the functionality of Filament, can have our content attached. Not sure yet of all the bits and pieces, but there has to be an easy and elegant way to implement your custom theme to Filament panel. I can imagine someone requesting you to work on a project and providing frontend/backend design so that we can attach the functionality required and we tell that our panel does not support the custom GUI ๐Ÿ™‚ I am sure it does, I just did not yet find it as I really love to use Filament and just need to invest some extra time in finding which template is where by design. I think that once I am done with the Vet clinic (or when the class is done with it) I can start by login/register form etc. and go slowly finding all the others, documenting their locations and think of a way or replacement that can be independent of the web framework. Maybe I am a dreamer but I am pretty sure if there is not a simple way to achieve the needed, there is a smart way to do so and the simple way is already in the DEV team minds....

how to set a value of an input field using values in a repeater

I have this input fields inside a repeater, product name, price and quantity, and I have an input field total disabled by default outside of the repeater, I want to populate the result of foreach(price * quantity) inside the total field
Solution:
myabe you can add the afterStateUpdated directly to the repeater instead of the input fields. Try using ->afterStateUpdated(fn ($state) => dd($state)) on the repeater and examine the results. It should be an array with all the items in the repeater. This will fire when you click the add action of the repeater and when you update items in the repeater. New empty items have a uuid key. But I imagine you can easily traverse the array, make calculatioins and set the value to the total. Let me kn...

Working on a Laravel Filament project using remote Shared Hosting

Hello guys. As part of my "training punishment" I decided to try to install a fresh Laravel + Filament project on my shared cPanel hosting and edit the files locally with a remote sync. Why am I trying this - simple, I switch PCs often as part of my IT work related day so having a centralized project space would allow me to edit from wherever whenever. So far, I've discovered a package provided from Micro$oft named RemoteSSH which allows you to connect to a shared host, lists all your files in the editor and you update directly. The issue with this approach is that when you need to transfer some files to the host, you can't copy/paste the folder or multiple files at once in VSCode (or at least it did not work with me to transfer 20Mb of assets). Besides that, the connection is reset quite often and it is almost impossible to reconnect without restarting the PC or else....
Solution:
Hmm, adding up to the need, when a dev works on a project and need to demonstrate/prove the progress to a client, eventually you would: 1. Want to have your website with the latest functionality UP-2-DATE 2. Not want to re-import DB, files etc. every time when a client need it. ...

is there a way to mutate data on createOptionForm in Select input.

i want to attach the creator_id before saving the form instead of having the a readonly field. ` Forms\Components\Select::make('payment_method_id') ->label('Payment Method') ->relationship(name: 'paymentMethod', titleAttribute: 'name')...

is there a way to make tabs filter optional according to roles

i have a teacher role and admin role, i want a tab filter only when i login as an admin, if i login as a teacher tab filter on the resource is not showing, is there a way to do that? thanks.
Solution:
Given that the getTabs() method returns the tabs you need as an array, You can easily customize the return value based on the user role. ```php public function getTabs(): array {...

Render data from two resources

Is there a way to render data in a form from two different resources (tables or models) without a relationship between them? Thanks

Need Help wrapping my mind around Filament implementation

Hello! I recently stumbled across this channel and love the content. Thank you for providing such great videos. Hoping this group can help me get a better understanding of how Filament might help me with a hobby project I am working on. Fair warning, I am not that great with Laravel, still learning. I am just here to get understanding and learn more. I want to create an application that let's different departments manage tasks, schedules, notes, etc. ...
Solution:
1) Users should be able to sign in and only see their tasks and other activities. I would imagine this happens outside of Filament? Does this mean there would be an admin login page but then also a user login page that pulls up their 'work page'? Yes, that seems to be more fitting than having only one panel (login page) and showing/hiding stuff based on roles. 2) Is Filament just a layer on top of Laravel to give admins access to their 'teams' but the bulk of the app should be handled outside, just in Laravel?...

how to share resources on both panels

i have 2 panel, teacher and stundet, i want to create a resource that accessible for both roles, thnaks.
Solution:
Panels need to have their own resource classes. But once you create them, the records of those resources are the same on both panels unless you scope them in some way, like a scope to the logged in user.

Custom setting page with filamentphp

I'm attempting to set up the edit page as the primary view for a filamentphp resource, specifically for managing page settings. These settings will consist of a single data row, and I want to restrict it to only being editable, with no option to create new rows or delete the existing one. Despite my efforts to find a solution, I haven't been able to. I'm open to any pointers, workarounds, or alternative approaches that could help me achieve this. Thanks for your assistance!

Validation doesn't work on form created with createOptionForm

Folks, I used the createOptionForm function to enable a new record creation form in a select field. Unfortunately, on this form, the unique() validation is not working. I followed a tip from Povilas in the code below, also without success: ```php // Document comes from a Leandro Ferreira package for document fields in pt_BR Document::make('cpf')
->label('CPF')...
Solution:
I implemented something similar, but without using any third party packages (Document) and the validation works as expected. Here's an example of a dropdown with the option to create a new user. The unique validation is added to the email field ```php Forms\Components\Select::make('owner_id') ->relationship('owner', 'name')...

TinyMce in filamentphp as a customField

I want to use TinyMCE in my form builder, but I can't. When I use the script inside my custom view, TinyMCE loads, but it disappears when I use a reactive() or any real-time functionality like a wizard. Additionally, when I hit "create", it won't send the data and I get the error "title cannot be null". I also tried registering the TinyMCE script file as the Filament documentation suggests (https://filamentphp.com/docs/3.x/support/assets#registering-javascript-files). I can see the script file when I inspect the page, but TinyMCE won't load. Here's my custom-textarea.blade.php file: ```<textarea{{ $applyStateBindingModifiers('wire:model') }}="{{ $getStatePath() }}"></textarea> <script src="https://cdn.tiny.cloud/1/cet2a3k5g1bxun5sp9vc8cka2nxji3ts1xrt1sz4h1oazm1g/tinymce/6/tinymce.min.js" referrerpolicy="origin"></script>...
No description