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

642
Views
How do I save array of data from laravel blade to database

I have this dumped output from the Laravel blade. In this, you can notice there is an array of amounts of data. Now, How do you save all the data, including an array, to the database?

Data From Form blade

array:9 [▼
  "_token" => "JjZqQiTv304JU65DNCli4MSjOsO0aqB84KVu8UgB"
  "category" => "Equestrian"
  "logistics" => "Barloworld"
  "currency" => "USD"
  "descriptions" => "Dolore labore cillum"
  "user_id" => "33"
  "m_description" => "Test"
  "ddate" => "2021-07-08"
  "amount" => array:2 [▼
    0 => "300"
    1 => null
  ]
]

Controller

        $data = $request->all();
        dd($data);
         $data = new Order();
        
         $data->amount = $request->get('amount');
         $data->m_description = $request->get('m_description');
         $data->ddate = $request->get('ddate');
         $data->currency = $request->get('currency');
         $data->descriptions = $request->get('descriptions');
         $data->logistics = $request->get('logistics');
         $data->category = $request->get('category');
         $data->code = $request->get('code');
         $data->user_id = $request->get('user_id');
         $data->save();
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

To save array you will have to use JSON format. Sometimes, you can use pivot tables to solve this problem but it has no sence to have pivot table for amount.

$data->amount = json_encode($request->get('amount'));

When getting data from database, you can make cast on model, or method which will return json_decode($this->amount)

If you would provide more information about what exactly could be in amount, I could answer better.

over 4 years ago · Santiago Trujillo Report

0

I think you can use model casting for array store in database

refer this link

https://laravel.com/docs/8.x/eloquent-mutators#array-and-json-casting

    protected $casts = [
            'amount' => 'array',
        ];
over 4 years ago · Santiago Trujillo Report

0

You can turn the data into a string by using either json_encode($array) or serialize($array). And then save the string to your database.

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!