laravel - Upload Image and save image path to database Lavavel 5.4 -


i creating new post on laravel. stuck here upload image , save image path database. controller is

if($request->hasfile('image'))         {             $image = $request->file('image');             $filename = time() . '.'. $image->getclientoriginalextension();              $path = public_path('images');             $imagepath = $request->image->move($path, $filename);             $post->image = $imagepath;          } 

but saves path 'c:\xampp\tmp\php2cf9.tmp'. causing error? or there better approaches this?

laravel can automaically save correct path you. first need setup local file storage, if haven't done (https://laravel.com/docs/5.4/filesystem#configuration)

then can fancy stuff like:

$post = new post(); $post->image = $request->file('image')->store('image'); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -