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
Can't you just create it, and set
protected static ?string $model = User::class;
?i tried that but im getting this
check here
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;
anyfix on that one?
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
?im trying to do a profile page
for the logged in user
I mean in the code. You get that error because somewhere it wants to use that class, which doesn't exist.
i already added the User model on the ProfileResource
my problem is the 2nd one picture
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.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
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
yes thats right
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
hmm now im confused ahahaha i dont really much understand the docs ahahha
Check out #profile
Oh, didn't know about that. Nice!
yea i just saw that package but you know i want to do it custom instead
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..
im trying that one thanks
ive tried and it seemd showing this error "Cannot use positional argument after named argument"
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 thisOk ill try it
#Create profile page of current logged user
hi what will be the next after this? how can i fetch the info of the authenticated user?
Check this also to include form https://filamentphp.com/docs/2.x/forms/getting-started#preparing-your-livewire-component
so its need to install the livewire?
No, the page you generated using
make:filament-page
is livewire page<?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>
yes.. correct..
This is normal livewire page, and everything like resource, widgets etc.. just try mount and dd(user)
its showing that
and is that your auth user?
public function user()
{
return Auth::user();
}
public function mount(): void
{
dd($this->user());
}
yes her
*here
Follow this to display your form on page
and my goal is to view a profile page with upload avatar something like that that the user can edit it
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
im confuse on those what will be using the livewire or the Pages?
"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
omg that works
now how can i achieve the editing the info?
can you explain more..
on that one its showing the info of the authenticated user and i want to add the ability to edit its info also
check this..