ahmad.alkaiyat's avatar

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
0 likes
4 replies
ahmad.alkaiyat's avatar

yes exactly! , Error message is "The photo id must be a file of type: jpeg, jpg, png ."

JackJones's avatar

If you remove the formrequest from the method and dd() the file, what does it say it is?

It should be an UploadedFile

Please or to participate in this conversation.