You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
<?php |
|
|
|
|
|
namespace App\Admin\Actions\Form; |
|
use Dcat\Admin\Widgets\Form; |
|
use Symfony\Component\HttpFoundation\Response; |
|
use App\Imports\DataExcel; |
|
use Maatwebsite\Excel\Facades\Excel; |
|
use Maatwebsite\Excel\Validators\ValidationException; |
|
use Throwable; |
|
|
|
class ImportExcelStudentForm extends Form |
|
{ |
|
public function handle(array $input) |
|
{ |
|
$file = env('APP_URL').'/upload/'.$input['file']; |
|
|
|
try { |
|
Excel::import(new DataExcel(time()), $input['file'],'public'); |
|
//dcat-2.0版本写法 |
|
return $this->response() |
|
->success('导入成功') |
|
->redirect('/admission_new_students'); |
|
|
|
} catch (ValidationException $validationException) { |
|
return Response::withException($validationException); |
|
} catch (Throwable $throwable) { |
|
//dcat 2.0写法 |
|
$this->response()->error(false); |
|
return $this->response()->error($throwable->getMessage())->refresh(); |
|
} |
|
} |
|
|
|
public function form() |
|
{ |
|
$this->file('file', '上传新生数据(Excel)')->rules('required', ['required' => '文件不能为空']); |
|
|
|
} |
|
|
|
} |
|
|
|
|