MoisesSegura
modifyQueryUsing with a role
I found a solution:
->modifyQueryUsing(fn (Builder $query): Builder =>
$query->when(auth()->user()->hasRole('Admin') === false, function ($query) {
return $query->where('country_id', auth()->user()->country_id);
}))
3 replies
I can't login into filament with a new user
yeah
->schema([
TextInput::make('name')
->required(),
TextInput::make('email')
->email()
->required(),
TextInput::make('password')
->password()
->hiddenOn('edit', true)
->required(),
Select::make('roles')->multiple()->relationship('roles','name')
]);
19 replies
modal doesn't save
trait Translatable
{
// This override get translations fields
protected function fillForm(): void
{
$this->callHook('beforeFill');
$data = $this->getRecord()->attributesToArray();
foreach (static::getRecord()->getTranslationsArray() as $key => $value) {
$data[$key] = $value;
}
$data = $this->mutateFormDataBeforeFill($data);
$this->form->fill($data);
$this->callHook('afterFill');
}
// This override get SQL optimization and get all translations
protected function getTableQuery(): Builder
{
return static::getResource()::getEloquentQuery()->with('translations');
}
}
35 replies
modal doesn't save
class Bibliography extends Model implements TranslatableContract
{
use HasFactory;
use Translatable;
protected $table = 'bibliography';
protected $guarded = [];
public $translatedAttributes = ['text'];
public $timestamps = false;
}
35 replies
modal doesn't save
only text but its associated with a translation table
CREATE TABLE
bibliography
(
id
int(11) NOT NULL AUTO_INCREMENT,
hide_locale
varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (id
)
) ENGINE=InnoDB AUTO_INCREMENT=347 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE bibliography_translation
(
id
int(11) NOT NULL AUTO_INCREMENT,
translatable_id
int(11) NOT NULL,
text
longtext COLLATE utf8_unicode_ci NOT NULL,
locale
varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (id
),
UNIQUE KEY bibliography_translation_uniq_trans
(translatable_id
,locale
),
KEY IDX_CDE13E762C2AC5D3
(translatable_id
),
CONSTRAINT FK_CDE13E762C2AC5D3
FOREIGN KEY (translatable_id
) REFERENCES bibliography
(id
) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=539 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;35 replies