0

The form portion of my view file is:

<form action="/admin/sliders" method="post" enctype="multipart/form-data">
                            {{ csrf_field() }}
                          <div class="row">
                            <div class="col-sm-3 form-group">
                              <h4 class="slide">Slide photo name</h4>
                            </div>
                            <div class="col-sm-8 form-group">
                              <input class="form-control inbox-del" id="slide_name" name="slider_name" placeholder="Add slide name" type="text">
                            </div>
                          </div> 
                          <div class="row">
                            <div class="col-sm-3 form-group">
                              <h4 class="slide">Add photo for slide</h4>
                            </div>
                            <div class="col-sm-6 form-group slide">
                                <input type="file" id="slider_link" name="slider_link" placeholder="Add a photo" >
                            </div>
                            <div class="col-sm-2 form-group">
                                <button class="btn btn-primary inbox-del pull-right"> Add Slider </button>
                            </div>
                          </div>
                        </form>

And the controller file is as follows:

public function store(Request $request){

$image = $request->file('image');
$filename = time().$image;
$gallery = new Slider;
$gallery->slider_name= $request->slider_name;
$gallery->slider_link = $filename;
$gallery->save();
$request->slider_link->move(public_path('uploaded'),$gallery->slider_name);
return $request->slider_link;

}

And I get the error: FatalErrorException Call to a member function move() on null. All the text data is inserted into the database. But the image is not placed in the uploaded directory.

1 Answer 1

1

You need to use getClientOriginalName function to get filename.

$image = $request->file('image')->getClientOriginalName();
Sign up to request clarification or add additional context in comments.

2 Comments

after adding that, now it's showing "Call to a member function getClientOriginalName() on null " error
Your name in input is slider_link not image. Update it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.