Answers for "laravel excel"

PHP
4

laravel excel

composer require maatwebsite/excel
Posted by: Guest on July-12-2021
0

laravel excel

//Install this package https://docs.laravel-excel.com/3.1/getting-started/installation.html
php artisan make:import UsersImport --model=User
<?php
namespace App\Imports;

use App\User;
use Illuminate\Support\Facades\Hash;
use Maatwebsite\Excel\Concerns\Importable;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithProgressBar;

class UsersImport implements ToModel, WithProgressBar
{
    use Importable;

    public function model(array $row)
    {
        return new User([
            'name'     => $row[0],
            'email'    => $row[1],
            'password' => Hash::make($row[2]),
        ]);
    }
}

//In your console command, you'd use it as follows:

<?php

namespace App\Console\Commands;

use App\Imports\UsersImport;
use Illuminate\Console\Command;

class ImportExcel extends Command
{
    protected $signature = 'import:excel';

    protected $description = 'Laravel Excel importer';

    public function handle()
    {
        $this->output->title('Starting import');
        (new UsersImport)->withOutput($this->output)->import('users.xlsx');
        $this->output->success('Import successful');
    }
}

// finally run this command
php artisan import:excel
Posted by: Guest on March-10-2021
1

laravel excel

namespace App\Imports;

use App\User;
use Maatwebsite\Excel\Concerns\ToModel;

class UsersImport implements ToModel
{

}
Posted by: Guest on October-17-2020
1

laravel excel

namespace App\Imports;

use App\User;
use Maatwebsite\Excel\Concerns\ToModel;

class UsersImport implements ToModel
{
    public function model(array $row)
    {
        return new User([
           'email'    => $row[1],
        ])
    }
}
Posted by: Guest on October-17-2020

Browse Popular Code Answers by Language