一、解决办法:
使用laravel内置的文件上传验证Request。
有时候,上传EXCEL时,虽然MIMES类型已经增加,但是验证就不通过,最后在mimes类型里增加了bin类型才解决。
1、最终验证Code:
<?php
namespace Modules\Finance\Http\Requests\MerchantsSettlement;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use App\Exceptions\APIHttpException;
class AttachmentRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
/*上传文件*/
'file' => 'bail|required|file|min:1|max:102400|mimes:png,jpg,gif,jpeg,pdf,zip,rar,doc,docx,bin,xls,xl