海工商新版后台
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

<?php
namespace App\Admin\Actions\Form;
use App\Imports\BedDataExcel;
use Dcat\Admin\Widgets\Form;
use Symfony\Component\HttpFoundation\Response;
use Maatwebsite\Excel\Facades\Excel;
use Maatwebsite\Excel\Validators\ValidationException;
use Throwable;
class ImportExcelBedForm extends Form
{
public function handle(array $input)
{
$file = env('APP_URL').'/upload/'.$input['file'];
try {
Excel::import(new BedDataExcel(time()), $input['file'],'public');
//dcat-2.0版本写法
return $this->response()
->success('导入成功')
->redirect('/allocation_dormitory_bed');
} 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' => '文件不能为空']);
}
}