|
@@ -6,6 +6,8 @@ use Illuminate\Http\Request;
|
|
|
use App\Models\Produit;
|
|
|
use App\Models\Categorie;
|
|
|
use App\Models\Media;
|
|
|
+use App\Models\CategorieProduit;
|
|
|
+
|
|
|
use App\Models\temporaryFile;
|
|
|
|
|
|
|
|
@@ -14,8 +16,12 @@ use Illuminate\Support\Facades\Storage;
|
|
|
class ProduitController extends Controller
|
|
|
{
|
|
|
public function Index(){
|
|
|
- $articles = Produit::with('categorie')->get();
|
|
|
|
|
|
+ $articles = Produit::get();
|
|
|
+
|
|
|
+
|
|
|
+ ;
|
|
|
+
|
|
|
|
|
|
return view("backend.produit.index",compact('articles'));
|
|
|
}
|
|
@@ -35,14 +41,17 @@ class ProduitController extends Controller
|
|
|
if($tmp_file){
|
|
|
Storage::copy('image/tmp/'.$tmp_file->folder.'/'.$tmp_file->file,'image/'.$tmp_file->folder.'/'.$tmp_file->file);
|
|
|
|
|
|
- Produit::create(
|
|
|
+ $article = Produit::create(
|
|
|
[
|
|
|
'nom' => $request->nom,
|
|
|
- 'category_id' => $request->input('categorie'),
|
|
|
+ // 'category_id' => $request->input('categorie'),
|
|
|
'description' => $request->description,
|
|
|
'image' => $tmp_file->folder . '/' . $tmp_file->file,
|
|
|
],
|
|
|
);
|
|
|
+
|
|
|
+ $article->categories()->sync((array)$request->input('categories'));
|
|
|
+
|
|
|
Storage::deleteDirectory('diapo/tmp/'.$tmp_file->folder);
|
|
|
$tmp_file->delete();
|
|
|
|
|
@@ -58,9 +67,15 @@ class ProduitController extends Controller
|
|
|
public function show($id){
|
|
|
$article=Produit::find($id);
|
|
|
$diapos=Media::where('produit_id','=',$article->id)->get();
|
|
|
+
|
|
|
+
|
|
|
+ $size = Storage::size('document/'.$article->document);
|
|
|
+ $file_size = $size * 0.0009765625;
|
|
|
+ $sizeFile = number_format($file_size,2);
|
|
|
|
|
|
-
|
|
|
- return view('backend.produit.show',['article'=>$article],compact('diapos'));
|
|
|
+ $infoPath = pathinfo(public_path('document/'.$article->document));
|
|
|
+ $extension = $infoPath['extension'];
|
|
|
+ return view('backend.produit.show',['article'=>$article],compact('diapos','sizeFile','extension'));
|
|
|
}
|
|
|
|
|
|
|
|
@@ -76,10 +91,13 @@ class ProduitController extends Controller
|
|
|
|
|
|
$article = Produit::find($id);
|
|
|
$article->nom = $request->input('nom');
|
|
|
- $article->category_id = $request->input('categorie');
|
|
|
+
|
|
|
|
|
|
$article->description = $request->input('description');
|
|
|
|
|
|
+ $article->categories()->sync((array)$request->input('categories'));
|
|
|
+
|
|
|
+
|
|
|
$tmp_file = temporaryFile::where('folder',$request->image)->first();
|
|
|
|
|
|
if($tmp_file){
|
|
@@ -296,12 +314,25 @@ if($tmp_file){
|
|
|
return response('');
|
|
|
}
|
|
|
}
|
|
|
-public function downloadDoc($id)
|
|
|
+public function downloadDoc(Produit $produit)
|
|
|
{
|
|
|
|
|
|
- $article = Produit::where('document', $id)->firstOrFail();
|
|
|
- return Storage::download('document/. $article->document');
|
|
|
-
|
|
|
+
|
|
|
+ return Storage::download('document/'.$produit->document);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+public function sizeDoc(Produit $produit)
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+ $size = Storage::size('document/'.$produit->document);
|
|
|
+ return view( compact('size'));
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|