85 lines
2.4 KiB
PHP
85 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\ProductPictograms;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Str;
|
|
|
|
class ProductPictogramsController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$pp = ProductPictograms::paginate();
|
|
return view('bo.product-pictograms.index', compact('pp'));
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
return view('bo.product-pictograms.create');
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$name = $request->name;
|
|
$picture = $request->picture;
|
|
|
|
$request->validate([
|
|
'name' => 'required|max:50',
|
|
'picture' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:max-width=150,max-height=80',
|
|
]);
|
|
|
|
$imageName = Str::slug($name) . '.' . $picture->extension();
|
|
$picture->move(public_path('uploads/images/pictos/'), $imageName);
|
|
|
|
$pp = new ProductPictograms();
|
|
$pp->name = $name;
|
|
$pp->picture = 'uploads/images/pictos/' . $imageName;
|
|
$pp->save();
|
|
|
|
return redirect()->route('bo.product-pictograms.index');
|
|
}
|
|
|
|
public function edit($id)
|
|
{
|
|
$pp = ProductPictograms::findOrFail($id);
|
|
return view('bo.product-pictograms.edit', compact('pp'));
|
|
}
|
|
|
|
public function update(Request $request, $id)
|
|
{
|
|
$name = $request->name;
|
|
$picture = $request->picture;
|
|
|
|
$request->validate([
|
|
'name' => 'required|max:50',
|
|
'picture' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:max-width=150,max-height=80',
|
|
]);
|
|
|
|
$imageName = Str::slug($name) . '.' . $picture->extension();
|
|
|
|
$pp = ProductPictograms::findOrFail($id);
|
|
Storage::delete(public_path('uploads/images/pictos/') . $pp->picture);
|
|
$picture->move(public_path('uploads/images/pictos/'), $imageName);
|
|
|
|
$pp->picture = 'uploads/images/pictos/' . $imageName;
|
|
$pp->save();
|
|
|
|
return redirect()->route('bo.product-pictograms.edit', ['product_pictogram' => $pp->id])
|
|
->with('success', __('Enregistré !'));
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
$pp = ProductPictograms::findOrFail($id);
|
|
$path = public_path() . '/' . $pp->picture;
|
|
if (file_exists($path)) {
|
|
unlink($path);
|
|
}
|
|
$pp->delete();
|
|
|
|
return redirect()->route('bo.product-pictograms.index');
|
|
}
|
|
}
|