Using 1 model in 2 Different Resource

i have this user model and i want to create a profile resource how can i use the user model in my profile resource?
47 Replies
John
John17mo ago
Can't you just create it, and set protected static ?string $model = User::class; ?
SIlentTech
SIlentTechOP17mo ago
SIlentTech
SIlentTechOP17mo ago
i tried that but im getting this check here
John
John17mo ago
Where is that coming from? Where in the code is it trying to include Resources\User ? Maybe find in all files. Did you try to create some resources and there are still files left behind from trial and error? Oh, maybe it's because you didn't use App\Models\User;
SIlentTech
SIlentTechOP17mo ago
SIlentTech
SIlentTechOP17mo ago
anyfix on that one?
John
John17mo ago
If you use an editor with autocomplete (e.g. PhpStorm), you will be notified of the missing class and it will automatically add the use. Please paste code with backticks and "php" as stated in #✅┊rules Yea that use seems ok. Where is it trying to include 'Resources\User?
SIlentTech
SIlentTechOP17mo ago
SIlentTech
SIlentTechOP17mo ago
im trying to do a profile page for the logged in user
John
John17mo ago
I mean in the code. You get that error because somewhere it wants to use that class, which doesn't exist.
SIlentTech
SIlentTechOP17mo ago
i already added the User model on the ProfileResource my problem is the 2nd one picture
John
John17mo ago
Did you remove the use App\Models\User; in the UserResource? Check the stack trace to see where it's trying to include that class.
SIlentTech
SIlentTechOP17mo ago
is there a better approach to do a profile page to a logged in user? im just new with filament wondering how to do that
John
John17mo ago
In that case I think you don't want a profile resource. A resource gives you a listing of records and you only want the current user to see/change their own, right? Start here; https://filamentphp.com/docs/2.x/admin/navigation#customizing-the-account-link
SIlentTech
SIlentTechOP17mo ago
yes thats right
John
John17mo ago
I think you should make a custom page https://filamentphp.com/docs/2.x/admin/pages/getting-started#creating-a-page and use in form in there if you want the user to edit their info: https://filamentphp.com/docs/2.x/forms/getting-started
SIlentTech
SIlentTechOP17mo ago
hmm now im confused ahahaha i dont really much understand the docs ahahha
Vp
Vp17mo ago
Check out #profile
John
John17mo ago
Oh, didn't know about that. Nice!
SIlentTech
SIlentTechOP17mo ago
yea i just saw that package but you know i want to do it custom instead
Vp
Vp17mo ago
Then follow this, it's very simple You also need to do this to link your new page with login name https://filamentphp.com/docs/2.x/admin/navigation#customizing-the-account-link If you still have a problem then we'll try to help you when you stuck..
SIlentTech
SIlentTechOP17mo ago
im trying that one thanks
SIlentTech
SIlentTechOP17mo ago
ive tried and it seemd showing this error "Cannot use positional argument after named argument"
Vp
Vp17mo ago
just give the route name like route('filament.pages.profile') Oh, you still trying to use "Resource" right? then it will not work, create a page and try this
SIlentTech
SIlentTechOP17mo ago
Ok ill try it
LeandroFerreira
LeandroFerreira17mo ago
#Create profile page of current logged user
SIlentTech
SIlentTechOP17mo ago
hi what will be the next after this? how can i fetch the info of the authenticated user?
Vp
Vp17mo ago
public User $user;

public function mount(): void
{
$this->user = auth()->user();
}
public User $user;

public function mount(): void
{
$this->user = auth()->user();
}
Check this also to include form https://filamentphp.com/docs/2.x/forms/getting-started#preparing-your-livewire-component
SIlentTech
SIlentTechOP17mo ago
so its need to install the livewire?
Vp
Vp17mo ago
No, the page you generated using make:filament-page is livewire page
SIlentTech
SIlentTechOP17mo ago
<?php namespace App\Filament\Pages; use App\Enums\UserRoleEnum; use App\Filament\Resources\ProfileResource; use Filament\Forms\Components\DatePicker; use Filament\Forms\Components\FileUpload; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Pages\Page; use Filament\Resources\Form; use Illuminate\Support\Facades\Auth; use PhpParser\Node\Expr\Closure; class Profile extends Page { protected static ?string $navigationIcon = 'heroicon-o-document-text'; protected static ?string $title = 'My Profile'; protected static ?string $navigationLabel = 'My Profile'; protected static ?string $slug = 'profile'; protected static bool $shouldRegisterNavigation = false; protected static string $view = 'filament.pages.profile'; public function user() { return Auth::user(); } } it generates that pages Profile.php and this filament page under views <x-filament::page> </x-filament::page>
Vp
Vp17mo ago
yes.. correct.. This is normal livewire page, and everything like resource, widgets etc.. just try mount and dd(user)
SIlentTech
SIlentTechOP17mo ago
SIlentTech
SIlentTechOP17mo ago
its showing that
Vp
Vp17mo ago
and is that your auth user?
SIlentTech
SIlentTechOP17mo ago
public function user() { return Auth::user(); } public function mount(): void { dd($this->user()); } yes her *here
Vp
Vp17mo ago
Follow this to display your form on page
SIlentTech
SIlentTechOP17mo ago
and my goal is to view a profile page with upload avatar something like that that the user can edit it
Vp
Vp17mo ago
Yes, to create form, file upload, input, select etc, you have to do it yourself. follow the link.. you'll understand easily https://gist.github.com/valpuia/0328cfbbe155154b0d78807a08564c86 Check this, this is how I create my profile.. you can understand a little bit from here
SIlentTech
SIlentTechOP17mo ago
SIlentTech
SIlentTechOP17mo ago
im confuse on those what will be using the livewire or the Pages?
Vp
Vp17mo ago
"Page classes are all full-page Livewire components with a few extra utilities you can use with the admin panel." read docs https://filamentphp.com/docs/2.x/admin/pages/getting-started#creating-a-page
SIlentTech
SIlentTechOP17mo ago
SIlentTech
SIlentTechOP17mo ago
omg that works now how can i achieve the editing the info?
Vp
Vp17mo ago
can you explain more..
SIlentTech
SIlentTechOP17mo ago
on that one its showing the info of the authenticated user and i want to add the ability to edit its info also
Vp
Vp17mo ago
check this..
Want results from more Discord servers?
Add your server