KinBH
Salve multiple relation
I have simple form:
Forms\Components\Select::make('competicoe_id')
->label('Competição')
->relationship(name: 'competicoes', titleAttribute: 'titulo')
->searchable()
->preload()
->required(),
Forms\Components\Select::make('atleta_id')
->label('Atletas')
->relationship(name: 'atletas', titleAttribute: 'nome')
->searchable()
->multiple()
->preload()
->required(),
My team table:
Schema::create('equipes', function (Blueprint $table) {
$table->id();
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable();
$table->timestamp('deleted_at')->nullable();
$table->unsignedBigInteger('atleta_id');
$table->unsignedBigInteger('competicoe_id');
$table
->foreign('atleta_id')
->references('id')
->on('atletas')
->onDelete('cascade')
->onUpdate('cascade');
$table
->foreign('competicoe_id')
->references('id')
->on('competicoes')
->onDelete('cascade')
->onUpdate('cascade');
});
Equipe Model:
public function atletas()
{
return $this->belongsTo(Atleta::class, 'atleta_id');
}
public function competicoes()
{
return $this->belongsTo(Competicoe::class, 'competicoe_id');
}
Atleta Model:
public function equipes()
{
return $this->hasOne(Equipes::class);
}
I select a competition and 3 athletes, but when i click o save return error
SQLSTATE[HY000]: General error: 1364 Field 'atleta_id' doesn't have a default value
INSERT INTO
equipes
(competicoe_id
, updated_at
, created_at
) VALUES (1, 2024-05-15 15:00:35, 2024-05-15 15:00:35)13 replies
Points with decimal
How to make automatic decimal(5,2)
i need put 12345 and automatic convert to 123.45 prefer in real time, but no problem if show after finish write. public static function form(Form $form): Form { return $form ->schema([ Forms\Components\TextInput::make('pontos') ->required() ->numeric() ->minValue(0),
i need put 12345 and automatic convert to 123.45 prefer in real time, but no problem if show after finish write. public static function form(Form $form): Form { return $form ->schema([ Forms\Components\TextInput::make('pontos') ->required() ->numeric() ->minValue(0),
6 replies
move getRelations() to especific area on form()
Is possible change position for :
public static function getRelations(): array
{
return [
DocumentoCompsRelationManager::class,
];
}
Problem: my last item on Form are multiple pictures, so my relation "fades away" in final on page, need something like this:
Forms\Components\RichEditor::make('texto')
->required()
->columnSpanFull(),
Forms\Components\Section::make(DocumentoCompsRelationManager::class)
Forms\Components\Section::make('Imagem chamada')
->hiddenLabel()
->collapsible()
->schema([
Forms\Components\FileUpload::make('image_chamada')
->hiddenLabel()
->minSize(20)
->multiple
->maxSize(6000)
->hint('Tamanho máximo permitido: 5mb.')
->acceptedFileTypes(['image/png', 'image/jpg', 'image/jpeg'])
->directory('competicoes/chamada')
]),
How i can do?
2 replies
Closure Upload Folder dynamic
How to use dynamic id based on select? Case: upload multiple pictures to one gallery. PS: i need save 1 file per line (file_name | galleryid)
My code:
return $form
->schema([
FileUpload::make('arquivo')
->image()
->maxSize(2048)
->multiple()
->disk('public')
// I need something like this:
// ->directory(function (UploadedFile $file) {
// return "fotos_galeria/{$file->get('galeria_id')}";
->uploadingMessage('Enviando arquivo...'),
Select::make('galeria_id')
->label('Galeria')
->relationship(name: 'galeria', titleAttribute: 'nome')
->searchable()
->preload()
]);
2 replies
How to get return from model to $form
App/Models/Jogo
class Jogo extends Model
{
use HasFactory, SoftDeletes;
protected $dates = ['deleted_at'];
public function generateslug() {
$slug = Str::random(6);
if (self::where('slug', $slug)->count() > 0) self::generateslug();
return $slug;
}
}
I want get this slug to put on my form
JogoResource
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Hidden::make('slug')
->disabled()
->default($slug_from_model_here),
5 replies