hamzajamshed152's avatar

When i am adding enctype="multipart/form-data" to my form it is not add image file name in my database and i also want to upload avatar in storage

Actually its working when i am not using enctype="multipart/form-data" but when i add it database is not adding my filename to it here is the form code

@csrf Full Name
                            </div>
                            <div class="form-group">
                                <label for="exampleInputEmail1">Email address</label>
                                <input type="email" value="{{ $data->email }}" name="email" class="form-control" id="user_email" placeholder="Enter Your Email">

                            </div>
                            <div class="form-group">
                                <label for="exampleInputFile">Profile Image</label>
                                <div class="input-group">
                                    <div class="custom-file">
                                        <input type="file" name="profile_pic" class="custom-file-input" id="profile-image">
                                        <label class="custom-file-label" for="exampleInputFile">Recommended Profile Image (160w x 160h)</label> 

                                    </div>
                                </div>
                                <span class="font-italic text-warning">Picture size should be less than 4MB</span>
                            </div>
                        </div>

                        <div class="card-footer">
                        <button type="submit" class="btn btn-primary">Submit</button>
                        </div>
                    </form>

and here is the controller code

public function update(Request $request)
{
    $userDetails = Auth::user(); 
    $user = User::find($userDetails ->id);  
    $user->full_name=$request->input('full_name');
    $user->email=$request->input('email');
    $user->profile_pic=$request->input('profile_pic');
    // if($request->hasFile('profile_pic'))
    // {
    //     $avatar = $request->file('profile_pic');

    //     $filename = time().'.'.$avatar->getClientOriginalExtension();
    //     $location = storage_path('app/public/uploads/'.$filename);
    //     Image::make($avatar)->resize(300, 300)->save($location);
    //     $user = Auth::user();
    //     $user->profile_pic = $filename;
    // }
    $user->save(); 
    return redirect()->back()->with('success','Sucessfully changed User Information');
}

And please also tell me how can i upload it to my storage because its not working !

0 likes
9 replies
MichalOravec's avatar

Can you explain me these two lines to me?

$userDetails = Auth::user(); 
$user = User::find($userDetails->id);  
hamzajamshed152's avatar

@Sinnbeck its here

@csrf Full Name
                            </div>
                            <div class="form-group">
                                <label for="exampleInputEmail1">Email address</label>
                                <input type="email" value="{{ $data->email }}" name="email" class="form-control" id="user_email" placeholder="Enter Your Email">

                            </div>
                            <div class="form-group">
                                <label for="exampleInputFile">Profile Image</label>
                                <div class="input-group">
                                    <div class="custom-file">
                                        <input type="file" name="profile_pic" class="custom-file-input" id="profile-image">
                                        <label class="custom-file-label" for="exampleInputFile">Recommended Profile Image (160w x 160h)</label> 

                                    </div>
                                </div>
                                <span class="font-italic text-warning">Picture size should be less than 4MB</span>
                            </div>
                        </div>

                        <div class="card-footer">
                        <button type="submit" class="btn btn-primary">Submit</button>
                        </div>
                    </form>
MichalOravec's avatar

And what about like this?

$user = Auth::user(); 

It's same right?

hamzajamshed152's avatar

@MichalOravec yeah it's the same right ... I delete the user details line can you tell me about whats the issue what's the issue when I am adding enctype to form

Please or to participate in this conversation.