updateOrCreate no work?

Posted 11 months ago by javineo

I have the following code in my controller:

<?php

namespace App\Http\Controllers;

use App\asm_padrone;
use Illuminate\Http\Request;
use Excel;




class ImportController extends Controller
{

    function csvToArray($filename = '', $delimiter = ',')
    {
        if (!file_exists($filename) || !is_readable($filename))
            return false;

        $header = null;
        $data = array();
        
        if (($handle = fopen($filename, 'r')) !== false)
        {
            while (($row = fgetcsv($handle, 1012, $delimiter)) !== false)
            {
                if (!$header)
                
                    $header = $row;
                    
                else        

                    $data[] = array_combine($header, $row);                     
                                      
            }                                
            fclose($handle);
        }
        return $data;
    }
    public function importCsv()
    {
        $file = public_path('padron.csv');

        $customerArr = $this->csvToArray($file);
        
        for ($i = 0; $i < count($customerArr); $i ++)
        {            
            asm_padrone::updateOrCreate($customerArr[$i]);
        }
        ($customerArr);
        return 'Jobi done or what ever';    
    }    
    
}

Then this model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class asm_padrone extends Model
{
    protected $table = 'asm_padrones';
    protected $fillable = [
        'nro_socio', 
        'nro_persona',
        'nombre_socio',
        'ingreso',
        'tipo_documento',
        'nro_documento',
        'zona',
        'domicilio_calle',
        'domicilio_nro',
        'domicilio_piso',
        'domicilio_dpto',
        'domicilio_adicional',
        'codigo_postal',
        'domicilio_localidad',
        'categoria_socio',
        'mail',
        'marca'
    ];
    public $timestamps = false;
}

I can not make an update.

Can someone help me with this problem?

Laravel 5.6 MySQL 5.7 PHP 7.1

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.