ffffer.
Use API authentication in Filament
Hi, I have a project with an API (sanctum tokens) and a panel in Filament. I would like to login with the API and continue the session in Filament.
Front consuming API and Filament panel are in the same domain, different subdomains.
What could be the best approach to do that? Thansk
5 replies
V4 needed
Hi, I need to use the V4, because I need to develop tables getting the data from a service rather than a model.
It's not a production project right now, but updating now to current v4 branch will allow me continue developing.
It's possible use the v4 branch now? I have tried to install but I didn't get running, mainly:
Problem 1
- Root composer.json requires filament/filament 4.x-dev (exact version match), found filament/filament[dev-3.x-alpha, v0.1.0, v1.0.0, ..., 1.x-dev, v2.0.0-beta1, ..., 2.x-dev, v3.0.0-alpha1, ..., 3.x-dev] but it does not match the constraint.
Btw, it's there docs for v4?
Thanks and sorry eagerness 🙂6 replies
RelationManager with relation having a morph
Ti, I have a RelationManager, and that model is related with a morphOne:
class RoundRelationManager extends RelationManager
{
protected static string $relationship = 'rounds';
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make('earlySale')
->label('Early Sale')
->schema([
Forms\Components\DateTimePicker::make('earlySale.start_at')
->label('Early sale Start')
->requiredWith('start_at')
->reactive()
//->formatStateUsing(fn($record) => $record->earlySale?->created_at?->format('Y-m-d H:i:s')),
,
Forms\Components\DateTimePicker::make('earlySale.finish_at')
->label('Early sale Finish')
->requiredWith('finish_at')
->reactive()
//->formatStateUsing(fn($record) => $record->earlySale?->finish_at?->format('Y-m-d H:i:s')),
])
->columns(2),
]);
In the model:
public function earlySale()
{
return $this->morphOne(EarlySale::class, 'saleable');
}
The problem is that without the formatStateUsing, the data is not loaded, and the problem is that (with and without formatStateUsing), the new values are not stored.
Ideas please?
thanks6 replies
Back to default within method
Hi,
If I have the following code:
Forms\Components\FileUpload::make('image')
->saveUploadedFileUsing(function() {
if($get('storage') == 'images') {
CODE
}
})
If the if is not satisfied, how can I get it to do the default method? That is, as if saveUploadedFileUsing has not been defined. My problem is that if the condition is not met, it doesn't work in all other cases.
Thanks
5 replies
FileUpload for Cloudflare Images
Hi,
I have a Forms\Components\FileUpload, and when editing, I want to show an image in a URL (not in the disk), something like:
Forms\Components\FileUpload::make('image')
->formatStateUsing(function($record) {
return 'https://picsum.photos/200';
})
(that code fails with error: foreach() argument must be of type array|object, string given)
How can I show the image in the URL?
Thanks8 replies
RelationManager select relationship with multiple(), Duplicate entry on update
Hi, the following code in a RelationManager:
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make()
->schema([
Forms\Components\Select::make('domains')
->relationship('domains','domain')
->multiple()
->preload(),
With a belongsToMany from both Models to each other. When creating, there is no problem, but when updating and add more domains, I get:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'assets_content_domain.PRIMARY'
insert into assets_content_domain
(assets_content_id
, domain_id
) values (1, 2)
Shouldn't it automatically manage that the record I am updating already exists? It's a bug?
Thanks10 replies
Builder schema not being reactive
Hi, I have this:
Forms\Components\Builder::make('requirements')
->blocks([
Forms\Components\Builder\Block::make('data')
->schema(function (callable $get) {
$type = $get('type');
Log::info($get('type'));
})
->reactive()
And:
Forms\Components\Section::make()
->schema([
Forms\Components\Select::make('other')
->options(function (callable $get) {
Log::info($get('type'));
return [$get('type')];
})
->reactive(),
Forms\Components\Select::make('type')
->options(['Option1' => 'Option1'])
->reactive()
->required(),
In the Builder Block::make('data'), the Log is empty, but in the Select::make('other'), the Log is Option1. Why?
How could I get the info from the select inside the Builder schema? Thanks5 replies
Query Builder stored in DB
Query Builder is great for filtering users depending on the many options it has, but I would like to be able to store that filter logic applied so I can run it in laravel every time I launch a script for example. Let's say I want to define the filters, store them in the db, and then use them in laravel from time to time (obviously if stored filters are called after a while, the results will be different, so I don't want to store the results)
Any ideas?
6 replies
Attach with dynamic fields
Hi, I'm trying to make a RelationManager attach, when a "Trigger" field is selected, show the fields of that Trigger, defined in an json options field (another option is a TriggersAttribute model). For example, the Trigger 'Signup', would have the fields:
'time_ago' (text)
country_id' (numeric)
Another Trigger will need different fields to be filled in. Let's say it is to make dynamic the attributes that I store in the pivot in a json.
I have come up with this code:
->headerActions([
AttachAction::make()
->preloadRecordSelect()
->recordTitleAttribute('name')
->form(function (AttachAction $action) {
return [
$action->getRecordSelect()
->reactive()
->afterStateUpdated(function (callable $set, $state) {
$trigger = Trigger::find($state);
if (!$trigger || empty($trigger->options)) {
return;
}
foreach ($trigger->options as $field => $config) {
if ($config['type'] == 'text') {
$set('dynamicFields.'.$field, $config);
}
}
}),
TextInput::make('dynamic_name')
->label('Name')
->visible(fn(callable $get) => $get('dynamicFields.name.type') === 'text'),
];
}),
])
But I don't get what I'm looking for, could you help me?5 replies
Table inside Infolist
Hello to all,
I would like to know if there is a way to insert a table into Infolist. I have infolist tabs, and in some of those tabs, I would like to have a table.
If not, I don't know if it would be possible to make a more complex structure, where there would be tabs containing infolist on one side and tables on the other.
Thanks for the advice, cheers
11 replies