public function add(Request $request)
{
$item=new item;
$item->Item_Name=$request->get('iname');
$item->Item_Category=$request->get('icat');
$item->Price=$request->get('price');
// $item->image_url=$request->get('img');
// below code the first line code where ('img') is form field name and last line before else
// image_url is database attribute name and $item is variable
if ($request->hasfile('img')) {
$file = $request->file('img');
$extension = $file->getClientOriginalExtension(); // getting image extension
$filename = time() . '.' . $extension;
$file->move('uploads/appsetting/', $filename);
//see above line.. path is set.(uploads/appsetting/..)->which goes to public->then create
//a folder->upload and appsetting, and it wil store the images in your file.
$item->image_url = $filename;
}
$item->Item_Type=$request->get('itype');
$item->save();
return redirect('/Menu_Item')->with('status','Record is successfully Inserted');;
}
To display the image in table from database
<img src="{{asset('uploads/appsetting/'.$item->image_url)}}" style="border-radius: 0px;" height="80px" width="60px;" />
0 Comments