|
2 | 2 |
|
3 | 3 | namespace App\Http\Controllers;
|
4 | 4 |
|
| 5 | +use App\Http\Helpers\Environment; |
5 | 6 | use App\Http\Requests\StoreProductRequest;
|
6 | 7 | use App\Models\Category;
|
7 | 8 | use App\Models\Product;
|
8 | 9 | use Illuminate\Http\Request;
|
| 10 | +use Illuminate\Support\Facades\Storage; |
9 | 11 |
|
10 | 12 | class ProductController extends Controller
|
11 | 13 | {
|
| 14 | + use Environment; |
12 | 15 | /**
|
13 | 16 | * Display a listing of the resource.
|
14 | 17 | *
|
@@ -64,15 +67,14 @@ public function store(StoreProductRequest $request)
|
64 | 67 | * "php artisan storage:link"
|
65 | 68 | * It will create the symlink.
|
66 | 69 | */
|
67 |
| - $path = $request->file('photo')->store('photos', 'public'); |
68 |
| - //dd($path); //dump&die |
| 70 | + $path = $request->file('photo')->store('photos', self::getStorageEnvironment()); |
69 | 71 |
|
70 | 72 | Product::create([
|
71 | 73 | 'name' => $request->name,
|
72 | 74 | 'price' => $request->price,
|
73 | 75 | 'category_id' => $request->category_id,
|
74 | 76 | 'description' => $request->description,
|
75 |
| - 'photo' => $path |
| 77 | + 'photo' => Storage::disk(self::getStorageEnvironment())->url($path) |
76 | 78 | ]);
|
77 | 79 | return redirect()->route('products.index');
|
78 | 80 | }
|
@@ -110,7 +112,7 @@ public function edit($id)
|
110 | 112 | */
|
111 | 113 | public function update(StoreProductRequest $request, $id)
|
112 | 114 | {
|
113 |
| - $path = $request->file('photo')->store('photos', 'public'); |
| 115 | + $path = $request->file('photo')->store('photos', self::getStorageEnvironment()); |
114 | 116 | $product = Product::findOrFail($id);
|
115 | 117 | $product->update([
|
116 | 118 | 'name' => $request->name,
|
|
0 commit comments