lundi 4 février 2019

Two byte character is not working in Laravel excel

I am using Laravel Excel package to import data from csv file to database. one of fmy filed is containing Japanese character(2-byte character). but when data is inserted to database all Japanese field is empty.

here is my code from controller

public function import( Request $request) 
    {

        if ($request->hasFile('import_file')) {

             Excel::import(new UsersImport, request()->file('import_file'));
        }

        return redirect('/')->with('success', 'All good!');
    }

UsersImport function:

use App\Item;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithChunkReading;
use Maatwebsite\Excel\Concerns\WithHeadingRow;

class UsersImport implements ToModel 
{

    public function model(array $row)
    {


        $row = collect($row);
        $chunks = $row->noHeading()->chunk(100);

        foreach($chunks as $chunk){ 
        return new Item([
            'title'     => $chunk[0],
            'description'    => $chunk[1], 
        ]);
    }
}

    /*public function chunkSize(): int
    {
        return 100;
    }*/
}

when i am putting english character inserting is working well.

one more problem is, i can not exclude the heading of my excel sheet.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire