Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

590
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda