jey
jey
Explore posts from servers
FFilament
Created by jey on 7/26/2024 in #❓┊help
how to show a modal when press next on wizard step
i have a wizard with many steps and i want to add/remove steps based on user action , this action will be via a modal popup we show at first step when user press next button , when user accept or decline we perform certain actions based on the input any help is appreciated
6 replies
FFilament
Created by jey on 7/25/2024 in #❓┊help
custom field viewData closure returns empty always
hi , im trying to make a custom item list cards for packages the following implementation works fine
class PackageCard extends Field
{
protected string $view = 'forms.components.package-card';
}

//in resource
PackageCard::make("package_id")
->viewData([
'packages' => Package::query()->get()
])
//package-card.blade.php:
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field"
wire:ignore
>
<div x-data="{ state: $wire.$entangle('{{ $getStatePath() }}') }">
<!-- Interact with the `state` property in Alpine.js -->
@foreach($packages as $package)
<p>{{$package->name}}</p>
@endforeach
</div>
</x-dynamic-component>
class PackageCard extends Field
{
protected string $view = 'forms.components.package-card';
}

//in resource
PackageCard::make("package_id")
->viewData([
'packages' => Package::query()->get()
])
//package-card.blade.php:
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field"
wire:ignore
>
<div x-data="{ state: $wire.$entangle('{{ $getStatePath() }}') }">
<!-- Interact with the `state` property in Alpine.js -->
@foreach($packages as $package)
<p>{{$package->name}}</p>
@endforeach
</div>
</x-dynamic-component>
however when i do the following it doesn't return anything ,
'packages' => fn(Forms\Get $get): Collection => Package::query()->where('country_id', $get("country_id"))->get()

//country select in the resource :

Select::make('country_id')
->options(Country::all()->pluck('name', 'id'))
->label(__("Country"))
->suffixIcon('heroicon-m-map-pin')
->hint(__("Please select the desired country of incorporation."))
->required()
->live()
->preload()
->searchable()
'packages' => fn(Forms\Get $get): Collection => Package::query()->where('country_id', $get("country_id"))->get()

//country select in the resource :

Select::make('country_id')
->options(Country::all()->pluck('name', 'id'))
->label(__("Country"))
->suffixIcon('heroicon-m-map-pin')
->hint(__("Please select the desired country of incorporation."))
->required()
->live()
->preload()
->searchable()
what am i missing or doing wrong ? any help is appreciated
28 replies
FFilament
Created by jey on 6/16/2024 in #❓┊help
send an email after creating a record
as title says , i want to send an email after creating a record , for example after creating a user via filament admin panel i want to notify the user via email about his new account ( simple example and similar to what i need )
9 replies
PPrisma
Created by jey on 5/22/2024 in #help-and-questions
user not saving on mongodb but works fine with mysql
hi , i was using mysql and switched to test mongodb , followed the docs on mongodb and my User model looks as follow now :
enum Role {
USER
MOD
ADMIN
}

model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
password String
subscriptionNumber String?
firstName String
lastName String
phone String?
isAccepted Boolean @default(false)
role Role
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
enum Role {
USER
MOD
ADMIN
}

model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
password String
subscriptionNumber String?
firstName String
lastName String
phone String?
isAccepted Boolean @default(false)
role Role
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
and this is my controller ( using express and ts ):
export const registerUser = async (req: Request, res: Response) => {
const { email, password, firstName, lastName, role, phone } = req.body;

try {
const salt = await bcrypt.genSalt(10);
const photo = req.file ? req.file.filename : 'default.jpg';
const userData: any = {
email: email,
password: await bcrypt.hash(password, salt),
firstName: firstName,
lastName: lastName,
role: role,
photo: photo,
phone: phone,
};

const user = await prisma.user.create({
data: userData,
});
console.log(user);
res.json(ok('NEW_USER_ADDED'));
} catch (err: any) {
if (err instanceof Prisma.PrismaClientKnownRequestError) {
if (err.code === 'P2002') {
res.status(400).json(error('EMAIL_IN_USE'));
}
}
return `${err.message}`;
}
};
export const registerUser = async (req: Request, res: Response) => {
const { email, password, firstName, lastName, role, phone } = req.body;

try {
const salt = await bcrypt.genSalt(10);
const photo = req.file ? req.file.filename : 'default.jpg';
const userData: any = {
email: email,
password: await bcrypt.hash(password, salt),
firstName: firstName,
lastName: lastName,
role: role,
photo: photo,
phone: phone,
};

const user = await prisma.user.create({
data: userData,
});
console.log(user);
res.json(ok('NEW_USER_ADDED'));
} catch (err: any) {
if (err instanceof Prisma.PrismaClientKnownRequestError) {
if (err.code === 'P2002') {
res.status(400).json(error('EMAIL_IN_USE'));
}
}
return `${err.message}`;
}
};
i'm sure the code is fine but still i have no idea what's going on wrong in here , i did push and generate my prisma and i see the tables fine in my mongodb compass any help is appreciated
4 replies
FFilament
Created by jey on 10/24/2023 in #❓┊help
show hidden fields conditionaly not working
as title says
Forms\Components\Checkbox::make('availability')->default(true),
Forms\Components\DatePicker::make('from')->hidden(fn(Get $get)=> $get('availability') === false),
Forms\Components\DatePicker::make('to')->hidden(fn(Get $get)=> $get('availability') === false),
Forms\Components\Checkbox::make('availability')->default(true),
Forms\Components\DatePicker::make('from')->hidden(fn(Get $get)=> $get('availability') === false),
Forms\Components\DatePicker::make('to')->hidden(fn(Get $get)=> $get('availability') === false),
4 replies
TtRPC
Created by jey on 10/21/2023 in #❓-help
Attempted import error: 'hashQueryKey' is not exported from '@tanstack/react-query' issue
i'm getting this error while trying trpc with latest next version , i tried downgrading but got another error Error: (0 , react__WEBPACK_IMPORTED_MODULE_3__.createContext) is not a function
2 replies
FFilament
Created by jey on 9/14/2023 in #❓┊help
draggable content
guys i want to create draggable content to be reordered in my crud , is there a way to achieve this? , like i want to display my categories as a tree ( see image ) to be reordered and save all the id's of categories that are available in the tree ( can delete only the image is just to show what i want to achieve ) any help is appreciated
3 replies
FFilament
Created by jey on 9/10/2023 in #❓┊help
how to save user_id on create and limit records per user
as the title says , i want to save current logged in user_id when i save a form that will associated with the user and how to limit user to create one only record , for example a user will create a business profile , i want him to be only able to create only one business profile not as many as he wants
15 replies