🤖transistor🤖
🤖transistor🤖
FFilament
Created by Gush on 3/12/2024 in #❓┊help
Button to create model in other resources
if your models are related and it's not too complicated (too many fields or complex conditions), you could do something like this: https://filamentphp.com/docs/3.x/panels/resources/relation-managers#creating-related-records If you want to create a different model (not related) you could create a Filament action, something like this:
Forms\Components\Actions\Action::make('my action')
->action(function(MyModel $my_model, MyAction $my_action) {
$my_action->execute($my_model);
})
]),
Forms\Components\Actions\Action::make('my action')
->action(function(MyModel $my_model, MyAction $my_action) {
$my_action->execute($my_model);
})
]),
if you need more data than the model, you can inject Get or the livewire instance. Then in your Laravel app, create an Action directory and create an action:
<?php

namespace App\Actions;

use App\Models\MyModel;

class MyAction
{
public function execute(MyModel $my_model): void
{
// do something
// save MyModel
}
}
<?php

namespace App\Actions;

use App\Models\MyModel;

class MyAction
{
public function execute(MyModel $my_model): void
{
// do something
// save MyModel
}
}
6 replies
FFilament
Created by nwalty on 3/12/2024 in #❓┊help
Best way to determine which resource a select component is currently being rendered on
To access the owner record you need to inject the livewire instance like so:
->options(function (RelationManager $livewire): array {
return $livewire->getOwnerRecord()->stores()
->pluck('name', 'id')
->toArray();
}),
->options(function (RelationManager $livewire): array {
return $livewire->getOwnerRecord()->stores()
->pluck('name', 'id')
->toArray();
}),
https://filamentphp.com/docs/3.x/panels/resources/relation-managers#accessing-the-relationships-owner-record so, if I understand correctly, Select::make('role_id') options depend on whether it is loaded under SchoolResource or ProgramResource, right? I would test the owner record to see if it contains a value from the parent resource to determine which options to load. Does this make sense?
4 replies
FFilament
Created by ChesterS on 2/27/2024 in #❓┊help
Create action with relation throws error
Seems to me that the relationship roles does not exist in your model, are you sure that's the correct name?
5 replies
FFilament
Created by Albert Lens on 2/27/2024 in #❓┊help
getFormActions / getCreateFormAction - Need to customize the save button to add more functionality
have you checked the Customizing the creation process in the docs? https://filamentphp.com/docs/3.x/panels/resources/creating-records#customizing-the-creation-process also check the Lifecycle hooks in that same page. If that doesn't cover you needs, then you need to create a Laravel Action, not a Filament action, there you will handle everything about your saving process and then maybe remove the default save button and replace it with your own, so that it invokes your action. Does this help?
4 replies
FFilament
Created by Ringer on 2/27/2024 in #❓┊help
Access record from text input column in table
have you tried injecting the Model $record in here?:
function (string $attribute, $value, Closure $fail) {
function (string $attribute, $value, Closure $fail) {
3 replies
FFilament
Created by Mohammad Ali on 2/27/2024 in #❓┊help
Resource table with date granularity
you seem to be looking for a db design, check this out (skip to the Hotels and rooms section) https://vertabelo.com/blog/a-database-model-for-a-hotel-reservation-booking-app-and-channel-manager/ no affiliation, just found it in my bookmarks
4 replies
FFilament
Created by CT on 2/27/2024 in #❓┊help
->disabled() on dependant Select broken on create page, works fine on edit modal.
have you tried empty instead of filled ? !filled($get('company_id')) -> !empty($get('company_id'))
6 replies
FFilament
Created by Clear on 2/26/2024 in #❓┊help
Dynamic form for a products attributes
One important thing is missing from your post, are you editing or creating a new record? Becuase the default property won't work on edit, only on create. If that's your case, you want to use the afterStateHydrated and inject your component and model record so you do something like this:
->afterStateHydrated(
function (Component $component, Model $record) {
$component->state($record->your_property);
}
)
->afterStateHydrated(
function (Component $component, Model $record) {
$component->state($record->your_property);
}
)
what throws me off is your loop, have you looked into Relation Managers? https://filamentphp.com/docs/3.x/panels/resources/relation-managers
3 replies
FFilament
Created by 🤖transistor🤖 on 2/26/2024 in #❓┊help
How the get the option label from a select
Found the solution:
Forms\Components\Select::make('exchange_rate_id')
->relationship('exchange_rate', 'rate')
->searchable()
->preload()
->live()
->afterStateUpdated(function (Select $component, Set $set, string $state) {
$val = $component->getOptions();
$set('exchange_rate', $val[$state]);
}),
TextInput::make('exchange_rate')
->numeric()
->key('exchangeRate')
Forms\Components\Select::make('exchange_rate_id')
->relationship('exchange_rate', 'rate')
->searchable()
->preload()
->live()
->afterStateUpdated(function (Select $component, Set $set, string $state) {
$val = $component->getOptions();
$set('exchange_rate', $val[$state]);
}),
TextInput::make('exchange_rate')
->numeric()
->key('exchangeRate')
5 replies
FFilament
Created by вєя. on 2/26/2024 in #❓┊help
Got Problem in Relation Table Column
happy to help, and get some sleep! 😉
16 replies
FFilament
Created by вєя. on 2/26/2024 in #❓┊help
Got Problem in Relation Table Column
if you changed the relationship name to author_model then use author_model.name in your table
16 replies
FFilament
Created by вєя. on 2/26/2024 in #❓┊help
Got Problem in Relation Table Column
ok, it looks like it's confusing the author property (which is the author id, right?) and the author relationship. try changing your relation to something different, like public function author_model(): BelongsTo or anything different from author and the use that as the relationship name.
16 replies
FFilament
Created by вєя. on 2/26/2024 in #❓┊help
Got Problem in Relation Table Column
assuming in your members table your primary key is id
16 replies
FFilament
Created by вєя. on 2/26/2024 in #❓┊help
Got Problem in Relation Table Column
I'm sorry if it wasn't clear, this is what I think your belongsTo relation should look like:
public function author(): BelongsTo
{
return $this->belongsTo(Member::class, 'author');
}
public function author(): BelongsTo
{
return $this->belongsTo(Member::class, 'author');
}
then you should be able to use author.name
16 replies
FFilament
Created by 🤖transistor🤖 on 2/26/2024 in #❓┊help
How the get the option label from a select
I thought that might be the case, but wanted to leave it as a last resort, to avoid more db calls
5 replies
FFilament
Created by вєя. on 2/26/2024 in #❓┊help
Got Problem in Relation Table Column
seems to me that your relationship to authors is not right in your Discussion model. The key should be your local key for authors, which seems to be author
16 replies
FFilament
Created by Dark on 12/7/2023 in #❓┊help
Toggle always false
I had the same issue, found that adding a ->default(0) to the TableColumn solves the issue:
Tables\Columns\IconColumn::make('email_verified_at')
->default(0)
Tables\Columns\IconColumn::make('email_verified_at')
->default(0)
40 replies
FFilament
Created by Np on 12/6/2023 in #❓┊help
custom action button can be used in multiple places
22 replies