我的控制器中有一个错误,我正在尝试从我的表单帖子验证我的图片上传。它在验证器功能上失败。我知道我到控制器的路由工作正常,因为如果我取消注释它工作的第一行并发回一个json。验证有什么问题。我很喜欢laravel。
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Storage;
use App\User as User;
class UserController extends Controller
{
public function uploadProfileImg(Request $request){
//return response()->json(['status'=>200,'request'=>$request->all()]);
$validator = Validator::make($request->all(), [
'file' => 'required|image|max:5500|mimes:jpeg,bmp,png'
]);
return response()->json(['status'=>200]);
}
}
答案 0 :(得分:1)
试试这个
public function uploadProfileImg(Request $request){
//return response()->json(['status'=>200,'request'=>$request->all()]);
$validator = Validator::make($request->all(), [
'file' => 'required|image|max:5500|mimes:jpeg,bmp,png'
]);
if ($validator->fails()) {
return redirect()->back()->withErrors($validator)
}
return response()->json(['status'=>200]);
刀片中的
@if(isset($errors))
@if($errors->all())
<ul style="list-style: none;" class="alert alert-warning">
@foreach($errors->all() as $content)
<li>{{$content}}</li>
@endforeach
</ul>
@endif
@endif