$ title = Item :: lists ('title') -> toArray ();
я получил сообщение об ошибке "Класс 'App \ Http \ Controllers \ Item' not found" извините, но я только что начал 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.";
}
}
}