ultimatepos/Modules/IndustrialEngineering/Http/Controllers/ProductPlatformController.php

76 lines
2.6 KiB
PHP

<?php
namespace Modules\IndustrialEngineering\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\IndustrialEngineering\Http\Controllers\Concerns\AuthorizesIndustrialEngineering;
use Modules\IndustrialEngineering\Models\LineTemplate;
use Modules\IndustrialEngineering\Models\ProductPlatform;
use Yajra\DataTables\Facades\DataTables;
class ProductPlatformController extends Controller
{
use AuthorizesIndustrialEngineering;
public function index(Request $request)
{
$this->authorizeIe('ie.platforms.view');
$businessId = $this->businessId();
if ($request->ajax()) {
return DataTables::of(ProductPlatform::forBusiness($businessId))
->addColumn('action', fn ($row) => '<a href="'.action([self::class, 'show'], $row->id).'" class="btn btn-xs btn-info"><i class="fa fa-layer-group"></i></a>')
->rawColumns(['action'])
->make(true);
}
return view('industrialengineering::product_platforms.index');
}
public function create()
{
$this->authorizeIe('ie.platforms.create');
return view('industrialengineering::product_platforms.create');
}
public function store(Request $request)
{
$this->authorizeIe('ie.platforms.create');
$data = $request->validate([
'platform_code' => 'required|string|max:100',
'name' => 'required|string|max:255',
'description' => 'nullable|string',
'industry_segment' => 'nullable|string|max:100',
'template_code' => 'nullable|string|max:100',
'template_name' => 'nullable|string|max:255',
]);
$data['business_id'] = $this->businessId();
$platform = ProductPlatform::create($data);
if ($request->filled('template_code')) {
LineTemplate::create([
'business_id' => $this->businessId(),
'product_platform_id' => $platform->id,
'template_code' => $request->input('template_code'),
'name' => $request->input('template_name', $platform->name),
]);
}
return redirect()->action([self::class, 'show'], $platform->id)
->with('status', ['success' => true, 'msg' => __('industrialengineering::lang.saved')]);
}
public function show($id)
{
$this->authorizeIe('ie.platforms.view');
$platform = ProductPlatform::forBusiness($this->businessId())
->with('lineTemplates.revisions')
->findOrFail($id);
return view('industrialengineering::product_platforms.show', compact('platform'));
}
}