vendredi 18 septembre 2015

FileNotFoundException in Filesystem.php line 381 When try to delete image

i'm bulding simple insert and delete function using laravel 5.0

However it give me an error :

FileNotFoundException in Filesystem.php line 381: File not found at path: public/img/products/xxxxxx.xxx

My Code is :

 public function postCreate(Requests\ProductRequest $request)
{
    $product = new Product;
    $product->category_id = Input::get('category_id');
    $product->title = Input::get('title');
    $product->description = Input::get('description');
    $product->price = Input::get('price');
    $product->status = Input::get('status');

    $image = Input::file('image');
    $filename  = date('m-d-Y-H_i_s')."-". $image->getClientOriginalName();
    $path = public_path('img/products/' . $filename);
    Image::make($image->getRealPath())->resize(468, 249)->save($path);
    $product->image = 'img/products/'.$filename;
    $product->save();
    return redirect('admin/products/')->with('flash_message','Product created');
}

public function postDestroy($id)
{
    $product = Product::find($id);
    if ($product) {
        Storage::delete('public/'.$product->image);
        $product->delete();
        return redirect('admin/products')->with('flash_message', 'Product deleted');
    }
    return redirect('admin/products')->with('flash_message','Something went wrong , please try again');
}

May i know what happen? i try few alternatives such :

File::delete (no error but image not deleted) \File::delete (no error but image not deleted)

Namespace :

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Product;
use App\Category;
use Request;
use Illuminate\Support\Facades\Input;
use Intervention\Image\Facades\Image;
use Illuminate\Support\Facades\Facade;
use Storage;
use League\Flysystem\Filesystem;
use File;



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire