I am testing the collections, and I have 2 doubts, the first is when I have arrived at the method where I am having problems when using LIKE. Given this collection
$coleccion = collection( [
['vehiculo' => 'toyota','propietario' => 'akio'],
['vehiculo' => 'opel','propietario' => 'rosari'],
['vehiculo' => 'mitsubishi','propietario' => 'ramon'],
['vehiculo' => 'reanult','propietario' => 'velvet'],
['vehiculo' => 'citroen','propietario' => 'anarella'],
['vehiculo' => 'mercedes','propietario' => 'juana'],
['vehiculo' => ['cadillac','toyota'],'propietario' => 'sandro'],
]);
$resultado = $coleccion->where('vehiculo','LIKE','"%opel%"');
dd($resultado)
The result variable I have tried it in several ways and in none of them I get any results
$resultado = $coleccion->where('vehiculo','LIKE',"%opel%");
$resultado = $coleccion->where('vehiculo','LIKE','%opel%');
$resultado = $coleccion->where('vehiculo','LIKE','"%op%"');
$resultado = $coleccion->where('vehiculo','like','"%opel%"');
$resultado = $coleccion->where('vehiculo','"%opel%"');
If I use this using a model, it works for me but not in this way.
My second doubt is the one that opens this post, I would like to combine in each of the arrays another key with another value, I have tried using combine, and merge and something I am doing wrong that does not combine it, simply add it to me at the end as a key more.
Starting from the same collection,
$coleccion = collection( [
['vehiculo' => 'toyota','propietario' => 'akio'],
['vehiculo' => 'opel','propietario' => 'rosari'],
['vehiculo' => 'mitsubishi','propietario' => 'ramon'],
['vehiculo' => 'reanult','propietario' => 'velvet'],
['vehiculo' => 'citroen','propietario' => 'anarella'],
['vehiculo' => 'mercedes','propietario' => 'juana'],
['vehiculo' => ['cadillac','toyota'],'propietario' => 'sandro'],
]);
I've tried like this
$combinados = $coleccion->merge([0 => ['cilindraje' => 100],1 => ['cilindraje' => 1000],2 => ['cilindraje' => 200], 3 => ['cilindraje' => 350],4 => ['cilindraje' => 488],5 => ['cilindraje' => 665],6 => ['cilindraje' => 147]]);
and so
$combinados = $coleccion->merge( ['cilindraje' => 100], ['cilindraje' => 1000],['cilindraje' => 200], ['cilindraje' => 350], ['cilindraje' => 488], ['cilindraje' => 665],['cilindraje' => 147]]);
and it does not work for me. As I say the final result should be this
$coleccion = collection( [
['vehiculo' => 'toyota','propietario' => 'akio','cilindraje' => 100],
['vehiculo' => 'opel','propietario' => 'rosari',cilindraje' => 1000],
['vehiculo' => 'mitsubishi','propietario' => 'ramon',cilindraje' => 200],
['vehiculo' => 'reanult','propietario' => 'velvet',cilindraje' => 350],
['vehiculo' => 'citroen','propietario' => 'anarella',cilindraje' => 488],
['vehiculo' => 'mercedes','propietario' => 'juana',cilindraje' => 665],
['vehiculo' => ['cadillac','toyota'],'propietario' => 'sandro',cilindraje' => 147],
]);