Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!