It gives an invalid file type error?
Sep 14, 2017
4
Level 1
Image Validation Error
Hello , I'm new to Laravel , and I created a form with an Image to be saved , I've created a Request to validate the Image type but the Issue is when i Pick a .png file for example its gives validation Error.
-form
{!! Form::open(['method'=>'POST', 'action'=> 'AdminCategoriesController@store','files'=>true]) !!}
<div class="form-group">
{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', null, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label('photo_id', 'Post Photo:') !!}
{!! Form::file('photo_id', null, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label('is_for_shop', 'Shop Related:') !!}
{!! Form::select('is_for_shop', array(1=>'yes', 0=>'No'),1, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::submit('Create Category', ['class'=>'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
-Controller
public function store(categoriesCreatRequest $request) { $input = $request->all();
$user = Auth::user();
$name = $request->name;
if($file =$request->file('photo_id')){
$name = time().$file->getClientOriginalName();
$file->move('images',$name);
$photo = Photo::create(['path'=>$name]);
$input['photo_id']=$photo->id;
}
Category::create($input);
return redirect('/admin/categories');
}
- Request
public function rules() { return [ // 'name' =>'required', 'photo_id' =>'required | mimes:jpeg,jpg,png | max:1000' ]; }
- uploaded File Asset 24.png
Please or to participate in this conversation.