Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
laravel excel添加flash消息,而不是NotTypeDetectedException_Laravel_Laravel Excel - Fatal编程技术网

laravel excel添加flash消息,而不是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

我正在使用软件包上传和使用excel文件与laravel。当我上传一个格式不受支持的文件(例如:-.doc文件)时,我会遇到这个异常

Maatwebsite\Excel\Exceptions\NotTypeDetectedException无消息

但是我需要用这样的闪光信息

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();
}