I'm trying to upload an image to database. Below is my code. When i upload my image it is stored as blob. So what should i do next? And how can i display the image ?
public function store(Request $request)
{
if(Auth::check()){
if (Stock::where('tag_no','=',$request->input('tag_no'))->exists()) {
return back()->withInput()->with('errors', 'Tag number already used!');
}
$stock = Stock::create([
'tag_no' => $request->input('tag_no'),
'image' => $request->input('image'),
'user_id' => Auth::user()->id
]);
if($stock){
return redirect()->route('stocks.index', ['stocks'=> $stock->tag_no])
->with('success' , 'Stock created successfully');
}
}
return back()->withInput()->with('errors', 'Error creating new Stock');
}
You do not 'store the image in the database'. There are 2 steps - store the image on the disk - some folder & then save THE PATH to the image into the database.
Then its as simple as Stock::where('id', 1)->first()->image to get the image path and display it.