File: /var/www/ivs.kaunokolegija.lt/laravel/app/Http/Controllers/Admin/CoopAgreementTypeController.php
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Traits\CsvImportTrait;
use App\Http\Requests\MassDestroyCoopAgreementTypeRequest;
use App\Http\Requests\StoreCoopAgreementTypeRequest;
use App\Http\Requests\UpdateCoopAgreementTypeRequest;
use App\Models\CoopAgreementType;
use Gate;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Yajra\DataTables\Facades\DataTables;
class CoopAgreementTypeController extends Controller
{
use CsvImportTrait;
public function index(Request $request)
{
abort_if(Gate::denies('coop_agreement_type_access'), Response::HTTP_FORBIDDEN, '403 Forbidden');
if ($request->ajax()) {
$query = CoopAgreementType::query()->select(sprintf('%s.*', (new CoopAgreementType)->table));
$table = Datatables::of($query);
$table->addColumn('placeholder', ' ');
$table->addColumn('actions', ' ');
$table->editColumn('actions', function ($row) {
$viewGate = 'coop_agreement_type_show';
$editGate = 'coop_agreement_type_edit';
$deleteGate = 'coop_agreement_type_delete';
$crudRoutePart = 'coop-agreement-types';
$modal = true;
$rowData = $row->name ?: '';
// dd('as cia');
return view('partials.datatablesActions', compact(
'viewGate',
'editGate',
'deleteGate',
'crudRoutePart',
'row',
'modal',
'rowData'
));
});
$table->editColumn('id', function ($row) {
return $row->id ? $row->id : '';
});
$table->editColumn('name', function ($row) {
return $row->name ? $row->name : '';
});
$table->rawColumns(['actions', 'placeholder']);
return $table->make(true);
}
return view('admin.coopAgreementTypes.index');
}
public function create()
{
abort_if(Gate::denies('coop_agreement_type_create'), Response::HTTP_FORBIDDEN, '403 Forbidden');
return view('admin.coopAgreementTypes.create');
}
public function store(StoreCoopAgreementTypeRequest $request)
{
$coopAgreementType = CoopAgreementType::create($request->all());
if ($request->ajax()) {
return response()->json([
'success' => true,
'message' => __('global.create_success'),
'data' => $coopAgreementType,
], 201);
}
return redirect()->route('admin.coop-agreement-types.index');
}
public function edit(CoopAgreementType $coopAgreementType)
{
abort_if(Gate::denies('coop_agreement_type_edit'), Response::HTTP_FORBIDDEN, '403 Forbidden');
return view('admin.coopAgreementTypes.edit', compact('coopAgreementType'));
}
public function update(UpdateCoopAgreementTypeRequest $request, CoopAgreementType $coopAgreementType)
{
$coopAgreementType->update($request->all());
if ($request->ajax()){
return response()->json([
'success' => true,
'data' => $coopAgreementType,
]);
}
return redirect()->route('admin.coop-agreement-types.index');
}
public function show(CoopAgreementType $coopAgreementType)
{
abort_if(Gate::denies('coop_agreement_type_show'), Response::HTTP_FORBIDDEN, '403 Forbidden');
$coopAgreementType->load('typeCoopAgreements');
return view('admin.coopAgreementTypes.show', compact('coopAgreementType'));
}
public function destroy(CoopAgreementType $coopAgreementType)
{
abort_if(Gate::denies('coop_agreement_type_delete'), Response::HTTP_FORBIDDEN, '403 Forbidden');
$coopAgreementType->delete();
return back();
}
public function massDestroy(MassDestroyCoopAgreementTypeRequest $request)
{
$coopAgreementTypes = CoopAgreementType::find(request('ids'));
foreach ($coopAgreementTypes as $coopAgreementType) {
$coopAgreementType->delete();
}
return response(null, Response::HTTP_NO_CONTENT);
}
}