Join WhatsApp ChannelJoin Now

How to upload blog Featured image in laravel

First of all, see screenshot and add this code your file.


          if($request->hasFile('images')){
            $file1 = $request->images; //Image from the browser
            $filename = time().'.'. $file1->getClientOriginalName(); //getting the extension an filename to save
            $location = public_path('images/post/' .$filename); //Your folder Location

            Image::make($file1)->save($location); 

            $pages ->images = $filename; //finally insert the filename into database.
          }
<form class="needs-validation" method="post"  action="{{ url('add-post') }}" novalidate enctype="multipart/form-data" >
   <input type = "hidden" name = "_token" value = "<?php echo csrf_token(); ?>">
    <div class="form-row">
    <div class="col-md-12 mb-3">
      <label for="image">Post Image</label>
      <input type="file" class="form-control-file" name="images" id="images">
    </div>
    </div>
    <button class="btn btn-primary" type="submit">Submit</button>
</form>

Recommended Posts