承接 jameron/import 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jameron/import

Composer 安装命令:

composer create-project jameron/import

包简介

A simle package to assist with importing data via csv.

关键字:

README 文档

README

This package has been built to work with Laravel 5.4.33 and later.

This package contains methods and traits that can be used with your project, and optionally you can use the views or just the view parials for your UX. If you are using the upload view, make sure you also require the admin package found here: Admin package

Your composer file would look like so:

        "jameron/admin": "*",
        "jameron/import": "*",

Some older versions may not be compatible. Let's see if we can't get you up and running in 10 steps. If you are starting fresh, create your laravel application first thing:

    composer create-project --prefer-dist laravel/laravel blog
  1. Add the package to your compose.json file:
    "jameron/import": "*",
composer update

**NOTE Laravel 5.5+ users there is auto-discovery so you can ignore steps 2 and 3

  1. Update your providers:
        Jameron\Regulator\ImportsServiceProvider::class,
  1. Update your Facades:
        'Imports' => Jameron\Regulator\Facades\ImportsFacade::class,
  1. Publish the views and config:
php artisan vendor:publish
  1. (Only if using Regulator for roles and permissions) Seed the database with import permission and assign permission to admin role

You can call it directly via command line or add it to your applications seeder file:

Added to application seeder

database/seeds/DatabaseSeeder.php

$this->call(\Jameron\Import\database\seeds\ImportSeeder::class);

Called via command line:

php artisan db:seed --class=\\Jameron\\Import\\database\\seeds\\ImportSeeder
  1. Update your webpack.mix.js file
   .js('resources/assets/import/js/upload.js', 'public/js/Upload.js')
   .sass('resources/assets/import/sass/upload.scss', 'public/css')
  1. Compile it up:
npm run dev
  1. Setup your routes and controllers
Route::group(['middleware' => ['web', 'auth', 'role:admin']], function () {
    Route::get('/import', 'ImportController@getImport');
    Route::post('/import', 'ImportController@postImport');
});
use \Jameron\Import\Http\Requests\ImportRequest;

class ImportController extends Controller
{

    public function getImport()
    {
        return view('import::upload');
    }

    public function postImport(ImportRequest $request)
    { 
        $csv = $request->file('csv');
        $headers_cleanup_rules = ['trim','pound_to_word_number','spaces_to_underscores', 'remove_special_characters','lowercase'];
        $import_model = \App\Models\QuizScores::class;
        $validator = \App\Http\Requests\QuizScoreRequest::class;

        $relationships = [
            [
                'create_if_not_found' => true,
                'csv_column' => 'student_id',
                'reference_table' => 'users',
                'reference_field' => 'student_identification_number',
                'reference_primary_key' => 'id',
                'foreign_key' => 'student_id',
                'relationship' => 'belongsTo',
                'model' => \App\Models\User::class,
                'validator' => \App\Http\Requests\UserRequest::class,
                'roles' => ['student'], // this only works for new users with the regulator package installed
                'extra_columns' => [
                    [
                        'column' => 'student_name',
                        'maps_to' => ['first_name','last_name'],
                        'explode_on' => ' '
                    ],
                    [
                        'column' => 'email',
                        'maps_to' => 'email',
                    ]
                ],
                'append_data' => [
                    'password' => \Hash::make('ChangeIt!')
                ]
            ],
            [
                'csv_column' => 'test_name',
                'reference_table' => 'tests',
                'reference_field' => 'name', // This assumes that the name field on the tests table has a rule that forces unique
                'reference_primary_key' => 'id', 
                'foreign_key' => 'test_id',
                'model' => \App\Models\Tests::class,
                'validator' => \App\Http\Requests\TestRequest::class,
            ] 
        ];
        
    }

}

统计信息

  • 总下载量: 65
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-12-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固