Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

upload image in laravel

<?php
  
namespace AppHttpControllers;
  
use IlluminateHttpRequest;
  
class ImageUploadController extends Controller
{
     /**
     * Display a listing of the resource.
     *
     * @return IlluminateHttpResponse
     */
    public function imageUpload()
    {
        return view('imageUpload');
    }
    
    /**
     * Display a listing of the resource.
     *
     * @return IlluminateHttpResponse
     */
    public function imageUploadPost(Request $request)
    {
        $request->validate([
            'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
        ]);
    
        $imageName = time().'.'.$request->image->extension();  
     
        $request->image->move(public_path('images'), $imageName);
  
        /* Store $imageName name in DATABASE from HERE */
    
        return back()
            ->with('success','You have successfully upload image.')
            ->with('image',$imageName); 
    }
}
Source by www.itsolutionstuff.com #
 
PREVIOUS NEXT
Tagged: #upload #image #laravel
ADD COMMENT
Topic
Name
9+9 =