Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

122
Visualizações
After PUT request object properties are shown as strings

Started working with Laravel 8 and little bit struggling with PUT request. Whenever I try to update(create actually new fields on update) a user with new properties they are shown as strings.

Here's my User migratiomn

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->id();
        $table->string('username');
        $table->string('password');
        $table->string('type')->nullable();
        $table->string('profile')->nullable();
        $table->timestamps();
    });
}

Here's my function from controller

  public function update(Request $request, $id)
    {
        $user = User::find($id);

        $user->update([
            'profile' => [
                'company_name' => $request->input('company_name'),
                'company_vat' => $request->input('company_vat'),
            ],
        ]);

        return response($user, 201);
    }

And here's how it looks from get request after doing put request. request

So the whole issue that they shouldn't be displayed as strings and actually I can't find a solution.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You need to add attribute casting to your model, it will save it as a json string in the database and json decode it on calls.

class User extends Model
{
    /**
     * The attributes that should be cast.
     *
     * @var array
     */
    protected $casts = [
        'profile' => 'array',
    ];
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda