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

588
Views
count(): Parameter must be an array or an object that implements Countable (laravel getting error)

I want to enter an multiple field entered data in table with for loop but i am getting an error in the post method.

error is

count(): Parameter must be an array or an object that implements Countable

controller code :-

$degree = $request->degree;
            for($i=0;$i<count($degree);$i++){
                $edu = new education;
                $edu->degree = $request->degree[i];
                $edu->clg = $request->clg[i];
                $edu->yoc = $request->yoc[i];
                $edu->save();
            }

so, please suggest me what i can do.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here not at all big problem,
you can not use count for the one value the array is required for that i think that you have not been enterd dynamically many values it can be 0

so replace code in your controller:-

$degree = $request->degree;
        if($degree > 0)
        {
            for($i=0;$i<count($degree);$i++){
                $edu = new education;
                $edu->degree = $request->degree[i];
                $edu->clg = $request->clg[i];
                $edu->yoc = $request->yoc[i];
                $edu->save();
            }
        }

here i have used $degree if its value is greater then 0 that means if it has value count grater then one then you can only go for loop and add value to database otherwise it will be not go in for loop

about 4 years ago · Juan Pablo Isaza 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!