mardi 21 août 2018

Wrong Image is being displayed

When I upload an image , there is no any error it works fine. But when the image is displayed it shows the wrong image. It's currently showing an image that doesn't even exist. To be true when i was testing the upload function i used the same image all the time so i really didnt find any problem. Now when i upload another image (minion's image) , it still display the old image that i used for testing purpose. I dont know why. I even checked inside the folder manually and inside the folder it shows the correct image but this is not the image that is shown in the view page .

Below is the code to store 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!');                
        } 

        $this->validate($request, [
        'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
        ]);

        $imageName = 'Tag '.$request->input('tag_no').'.'.$request->image->getClientOriginalExtension();
        $request->image->move(public_path('/storage/'.Auth::user()->company.'/stock-images'), $imageName);   

        $stock = Stock::insert([
            'tag_no' => $request->input('tag_no'),
            'stock_type' => $request->input('stock_type'),                                  
            'image' => $imageName,
        ]);            

        if($stock){                   
            return redirect()->route('stocks.index')
            ->with('success' , 'Stock created successfully');
        }                
    }        
    return back()->withInput()->with('errors', 'Error creating new Stock');        
}

So the path I'm storing is in " /public/storage/companyname/stock-images/ ".

And in the view page:

 <a href="/storage//stock-images/" target="__blank">
 <img class="pull-right" src="/storage//stock-images/"  height="100" width="100"></a>

I tried clearing cache and config and also view still its the same. Someone please suggest me something.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire