File "AttributeOptionController.php"
Full Path: /home/clickysoft/public_html/jmapi5.clickysoft.net/app/Http/Controllers/Admin/AttributeOptionController.php
File size: 3.96 KB
MIME-type: text/x-php
Charset: utf-8
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\MassDestroyAttributeOptionRequest;
use App\Http\Requests\Admin\StoreAttributeOptionRequest;
use App\Http\Requests\Admin\UpdateAttributeOptionRequest;
use App\Models\Attribute;
use App\Models\AttributeOption;
use Gate;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Yajra\DataTables\Facades\DataTables;
class AttributeOptionController extends Controller
{
public function index(Request $request)
{
abort_if(Gate::denies('attribute_option_access'), Response::HTTP_FORBIDDEN, '403 Forbidden');
if ($request->ajax()) {
$query = AttributeOption::with(['attribute'])->select(sprintf('%s.*', (new AttributeOption())->table));
$table = Datatables::of($query);
$table->addColumn('placeholder', ' ');
$table->addColumn('actions', ' ');
$table->editColumn('actions', function ($row) {
$viewGate = 'attribute_option_show';
$editGate = 'attribute_option_edit';
$deleteGate = 'attribute_option_delete';
$crudRoutePart = 'attribute-options';
return view('partials.datatablesActions', compact(
'viewGate',
'editGate',
'deleteGate',
'crudRoutePart',
'row'
));
});
$table->editColumn('id', function ($row) {
return $row->id ? $row->id : '';
});
$table->addColumn('attribute_name', function ($row) {
return $row->attribute ? $row->attribute->name : '';
});
$table->editColumn('name', function ($row) {
return $row->name ? $row->name : '';
});
$table->rawColumns(['actions', 'placeholder', 'attribute']);
return $table->make(true);
}
$attributes = Attribute::get();
return view('admin.attributeOptions.index', compact('attributes'));
}
public function create()
{
abort_if(Gate::denies('attribute_option_create'), Response::HTTP_FORBIDDEN, '403 Forbidden');
$attributes = Attribute::pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');
return view('admin.attributeOptions.create', compact('attributes'));
}
public function store(StoreAttributeOptionRequest $request)
{
$attributeOption = AttributeOption::create($request->all());
return redirect()->route('admin.attribute-options.index');
}
public function edit(AttributeOption $attributeOption)
{
abort_if(Gate::denies('attribute_option_edit'), Response::HTTP_FORBIDDEN, '403 Forbidden');
$attributes = Attribute::pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');
$attributeOption->load('attribute');
return view('admin.attributeOptions.edit', compact('attributeOption', 'attributes'));
}
public function update(UpdateAttributeOptionRequest $request, AttributeOption $attributeOption)
{
$attributeOption->update($request->all());
return redirect()->route('admin.attribute-options.index');
}
public function show(AttributeOption $attributeOption)
{
abort_if(Gate::denies('attribute_option_show'), Response::HTTP_FORBIDDEN, '403 Forbidden');
$attributeOption->load('attribute');
return view('admin.attributeOptions.show', compact('attributeOption'));
}
public function destroy(AttributeOption $attributeOption)
{
abort_if(Gate::denies('attribute_option_delete'), Response::HTTP_FORBIDDEN, '403 Forbidden');
$attributeOption->delete();
return back();
}
public function massDestroy(MassDestroyAttributeOptionRequest $request)
{
AttributeOption::whereIn('id', request('ids'))->delete();
return response(null, Response::HTTP_NO_CONTENT);
}
}