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

176
Vistas
Laravel intersect wont get input

I have an intersect in my update method:

$inputs = $request->intersect('message','name','email','is_read');

If i send an update request where is_read=0 the intersect returns an empty array. Works fine with anything else (false, 1 etc)

Any tips?

Thanks!

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

ALERT Try to move to another implementation and stop using intersect() method, it will be removed from the future versions of Laravel: Link

IF you mean that the is_read key is missing from the final array (and not the the whole array is empty, see my comment), this is because of the implementation of the intersect() method.

The intersect method simply wraps the only() method of the Illuminate\Http\Request class and do an array_filter over the result.

This is the implementation:

/**
 * Intersect an array of items with the input data.
 *
 * @param  array|mixed  $keys
 * @return array
 */
public function intersect($keys)
{
    return array_filter($this->only(is_array($keys) ? $keys : func_get_args()));
}

In your case, we can decompose the code as this:

step1

$results = $request->only('message','name','email','is_read');

At this point, $results is

Array
(
    [message] => message
    [name] => name
    [email] => email
    [is_read] => 0
)

However, at step2

step2

$filteredResults = array_filter($results);

The result becomes

Array
(
    [message] => message
    [name] => name
    [email] => email
)

And this is because of how array_filter works. It expect an array as the first parameter, then an optional callback (used to filter the array) and a flag.

From php reference

What happens when no callback is provided (like in this case?)

If no callback is supplied, all entries of array equal to FALSE (see converting to boolean) will be removed.

If you look at the link converting to boolean you'll see that 0 (zero) is assumed to be FALSE and, for that reason, removed from the array.

about 4 years ago · Santiago Trujillo 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