前提・実現したいこと
Laravelで画像を読み込んでもバリデーションで引っかからないようにしたい。
発生している問題・エラーメッセージ
画像を入れてもこのエラーが出ます。 The image must be an image. The image must be a file of type: jpg, jpeg, png.
該当のソースコード
コントローラ <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Post; use Auth; class PostsController extends Controller { public function store(Request $request){ $request->validate([ 'description'=>'required', 'image'=>'required|image|mimes:jpg,jpeg,png|max:2000', ]); $post=new Post; $post->description=$request->description; $post->user_id=Auth::user()->id; if($request->hasFile('image')){ $file=$request->file('image')->store('images','public'); $post->image=$file; } $post->save(); return back(); } } ビュー <form action="{{route('posts.store')}}" method="post"> {{csrf_field()}} <div class="form-group"> <input type="file" name="image" class="form-control"> </div> <div class="form-group"> <textarea name="description" class="form-control" placeholder="コメント..."></textarea> </div> <button type="submit" class="btn btn-info btn-block">保存</button> </form> ルーティング Route::post('/posts','PostsController@store')->name('posts.store'); ### 試したこと ここに問題に対して試したことを記載してください。 ### 補足情報(FW/ツールのバージョンなど) ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー