124 lines
3.7 KiB
PHP
124 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\DataTables\SubJobDataTable;
|
|
use App\Http\Requests\StoreSubJobRequest;
|
|
use App\Http\Requests\UpdateSubJobRequest;
|
|
use App\Models\Directorat;
|
|
use App\Models\Job;
|
|
use App\Models\SubJob;
|
|
use Illuminate\Http\Request;
|
|
|
|
class SubJobController 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(SubJobDataTable $dataTable)
|
|
{
|
|
/*if (is_null($this->user) || !$this->user->can('masters.read')) {
|
|
abort(403, 'Sorry !! You are Unauthorized to view any master data !');
|
|
}*/
|
|
addVendor('chained-select');
|
|
|
|
$directorat = Directorat::all();
|
|
return $dataTable->render('pages.masters.sub-job.index', compact('directorat'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create(){}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(StoreSubJobRequest $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 SubJob...
|
|
if($validated){
|
|
try{
|
|
SubJob::create($validated);
|
|
//return redirect()->route('job.index')->with('success', 'SubJob created successfully.');
|
|
echo json_encode(['status' => 'success', 'message' => 'Sub Job created successfully.']);
|
|
}catch(\Exception $e){
|
|
//return redirect()->route('job.index')->with('error', 'SubJob created failed.');
|
|
echo json_encode(['status' => 'error', 'message' => 'Sub Job created failed.']);
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(SubJob $subJob)
|
|
{
|
|
echo json_encode($subJob);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit($id){
|
|
$subJob = SubJob::find($id);
|
|
echo json_encode($subJob);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(UpdateSubJobRequest $request, SubJob $subJob)
|
|
{
|
|
/*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 SubJob...
|
|
if($validated){
|
|
try{
|
|
$subJob->update($validated);
|
|
//return redirect()->route('job.index')->with('success', 'SubJob updated successfully.');
|
|
echo json_encode(['status' => 'success', 'message' => 'Sub Job updated successfully.']);
|
|
}catch(\Exception $e){
|
|
//return redirect()->route('job.index')->with('error', 'SubJob updated failed.');
|
|
echo json_encode(['status' => 'error', 'message' => 'Sub Job updated failed.']);
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(SubJob $subJob){
|
|
$subJob->delete();
|
|
echo json_encode(['status' => 'success', 'message' => 'Sub Job deleted successfully.']);
|
|
//return redirect()->route('sub-job.index')->with('success', 'Sub Job deleted successfully.');
|
|
}
|
|
}
|