他通常和我一起工作,直到出现一些问题。 我导入Excel文件时出现问题,没有结果或错误。仅空白页。 如果在导入后添加重定向代码,他会将我重定向到无数据。
我找不到问题,因为我检查了我的代码并进行测试以转储行dump($row)
,但相同的问题是空白页!
我试图删除该程序包,然后重新安装它。
您还检查数据库和控制器并成功工作
Imports/WordsImport
:
<?php
namespace App\Imports;
use App\WordsList;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithBatchInserts;
use Maatwebsite\Excel\Concerns\WithChunkReading;
class WordsImport implements ToModel, WithBatchInserts, WithChunkReading
{
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function model(array $row)
{
if (!isset($row[0])) {
return null;
}
return new WordsList([
'Translation' => $row[1],
'EnglishPos' => $row[2],
'EnglishWave' => $row[3],
'Word' => $row[4],
'SimpleWords' => $row[5],
'ArabicPos' => $row[6],
'ArabicWave' => $row[7],
'ArabicSense' => $row[8],
'Synonyms' => $row[9],
'Antonyms' => $row[10]
]);
}
public function batchSize(): int
{
return 1000;
}
public function chunkSize(): int
{
return 10000000000;
}
}
Controller .. /ImportWordsController
:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Imports\WordsImport;
use Maatwebsite\Excel\Facades\Excel;
class ImportWordsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('ImportWords');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'select_file' => 'required|mimes:xls,xlsx',
]);
Excel::import(new WordsImport, request()->file('select_file'));
//return redirect('/dashboard/wordslist')
// ->with('success','The word has been Uploaded successfully');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}