【发布时间】:2018-10-26 08:19:31
【问题描述】:
$titles = Item::lists('title')->toArray();
我收到错误“找不到类 'App\Http\Controllers\Item'”对不起,但我今天才开始使用 laravel :'(
我刚刚在stackoverflow中得到了这段代码:(
public function excel_import(Request $request){
$file = Input::file('file');
$file_name= $file->getClientOriginalName();
$file->move('files',$file_name);
$titles = Item::lists('title')->toArray();
if($request->hasFile('file')){
$path = $request->file('file')->getRealPath();
$data = Excel::load('files/'.$file_name, function($reader) {
$reader->all();
})->get();
if(!empty($data) && $data->count()){
$insert = array();
foreach ($data as $key => $value) {
if (in_array($value->title, $titles))
continue;
$insert[] = array(
'ke_y' => $value['ke_y'],
'en' => $value['en'],
);
$titles[] = $value->title;
}
}
if(!empty($insert)){
DB::table('matrix_localization')->insert($insert);
echo "all good. ";
}
else {
echo "Please Check your file, Something is wrong there.";
}
}
}
【问题讨论】:
-
您好!如果您发布任何人都可以在他们的机器上执行的代码,它会帮助人们。这样就更容易为您提供帮助。见本站:minimal reproducible example
-
在顶部添加导入语句:
use Item;