laravel excel添加flash消息,而不是NotTypeDetectedException
我正在使用软件包上传和使用excel文件与laravel。当我上传一个格式不受支持的文件(例如:-.doc文件)时,我会遇到这个异常 Maatwebsite\Excel\Exceptions\NotTypeDetectedException无消息 但是我需要用这样的闪光信息laravel excel添加flash消息,而不是NotTypeDetectedException,laravel,laravel-excel,Laravel,Laravel Excel,我正在使用软件包上传和使用excel文件与laravel。当我上传一个格式不受支持的文件(例如:-.doc文件)时,我会遇到这个异常 Maatwebsite\Excel\Exceptions\NotTypeDetectedException无消息 但是我需要用这样的闪光信息 flash("Sorry you are using a wrong format to upload files.")->error(); return Redirect::back(); 这是我的密码 $file
flash("Sorry you are using a wrong format to upload files.")->error();
return Redirect::back();
这是我的密码
$file = $request->file('file');
Excel::import(new MyImport, $file);
这是我的导入文件
<?php
namespace App\Imports;
use Maatwebsite\Excel\Concerns\ToModel;
class MyImport implements ToModel
{
public function model(array $row)
{
...
}
}
导入文件顶部的异常:
use Maatwebsite\Excel\Exceptions\NoTypeDetectedException;
并使用块捕获异常:
try {
Excel::import(new MyImport, $file);
} catch (NoTypeDetectedException $e) {
flash("Sorry you are using a wrong format to upload files.")->error();
return Redirect::back();
}