120 lines
3.7 KiB
PHP
120 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\DataTables\DirectoratDataTable;
|
|
use App\Http\Requests\StoreDirectoratRequest;
|
|
use App\Http\Requests\UpdateDirectoratRequest;
|
|
use App\Models\Directorat;
|
|
use Illuminate\Http\Request;
|
|
|
|
class DirectoratController extends Controller
|
|
{
|
|
public $user;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->middleware(function ($request, $next) {
|
|
//$this->user = Auth::guard('web')->user();
|
|
return $next($request);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index(DirectoratDataTable $dataTable)
|
|
{
|
|
/*if (is_null($this->user) || !$this->user->can('masters.read')) {
|
|
abort(403, 'Sorry !! You are Unauthorized to view any master data !');
|
|
}*/
|
|
|
|
return $dataTable->render('pages.masters.directorat.index');
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create(){}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(StoreDirectoratRequest $request)
|
|
{
|
|
/*if (is_null($this->user) || !$this->user->can('masters.create')) {
|
|
abort(403, 'Sorry !! You are Unauthorized to create any master data !');
|
|
}*/
|
|
|
|
|
|
// Validate the request...
|
|
$validated = $request->validated();
|
|
|
|
// Store the Directorat...
|
|
if($validated){
|
|
try{
|
|
Directorat::create($validated);
|
|
//return redirect()->route('directorat.index')->with('success', 'Directorat created successfully.');
|
|
echo json_encode(['status' => 'success', 'message' => 'Directorat created successfully.']);
|
|
}catch(\Exception $e){
|
|
//return redirect()->route('directorat.index')->with('error', 'Directorat created failed.');
|
|
echo json_encode(['status' => 'error', 'message' => 'Directorat created failed.']);
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(Directorat $directorat)
|
|
{
|
|
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit($id){
|
|
$directorat = Directorat::find($id);
|
|
echo json_encode($directorat);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(UpdateDirectoratRequest $request, Directorat $directorat)
|
|
{
|
|
/*if (is_null($this->user) || !$this->user->can('masters.update')) {
|
|
abort(403, 'Sorry !! You are Unauthorized to update any master data !');
|
|
}*/
|
|
|
|
// Validate the request...
|
|
$validated = $request->validated();
|
|
|
|
// Update the Directorat...
|
|
if($validated){
|
|
try{
|
|
$directorat->update($validated);
|
|
//return redirect()->route('directorat.index')->with('success', 'Directorat updated successfully.');
|
|
echo json_encode(['status' => 'success', 'message' => 'Directorat updated successfully.']);
|
|
}catch(\Exception $e){
|
|
//return redirect()->route('directorat.index')->with('error', 'Directorat updated failed.');
|
|
echo json_encode(['status' => 'error', 'message' => 'Directorat updated failed.']);
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(Directorat $directorat){
|
|
$directorat->delete();
|
|
echo json_encode(['status' => 'success', 'message' => 'Directorat deleted successfully.']);
|
|
//return redirect()->route('directorat.index')->with('success', 'Directorat deleted successfully.');
|
|
}
|
|
}
|