first();
abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User');
if ($request->ajax()) {
$data = DB::table('works as w')->leftJoin('categories as c', 'c.id', '=', 'w.category_id')->select('w.shortname as shortname', 'w.id as work_id', 'w.name as name', 'w.desc as desc', 'c.name as category_name', 'w.category_id as category_id');
return DataTables::of($data)->addIndexColumn()
->addColumn('action', function($row) use ($menu) {
$btn = '
';
// Products Management Button
if(Gate::allows('view', $menu)) {
$btn .= '
Produk
';
}
if(Gate::allows('update', $menu)) {
$btn .= '
Edit
';
}
if(Gate::allows('delete', $menu)) {
$btn .= '
Hapus
';
}
$btn .= '
';
return $btn;
})
->rawColumns(['action'])
->make(true);
}
$categories = Category::all();
return view('back.master.work', compact('categories'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$menu = Menu::where('link', 'work.index')->first();
abort_if(Gate::denies('create', $menu), 403, 'Unauthorized User');
Work::create($request->all());
$response = [
"status" => 200,
"message" => "Data created successfully"
];
return response()->json($response);
}
/**
* Display the specified resource.
*
* @param \App\Models\Work $work
* @return \Illuminate\Http\Response
*/
public function show(Work $work)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Work $work
* @return \Illuminate\Http\Response
*/
public function edit(Work $work)
{
$menu = Menu::where('link', 'work.index')->first();
abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User');
$work = Work::find($work->id);
$response = [
'data' => $work,
'status' => 200,
'message' => 'get data successfully'
];
return response()->json($response);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Work $work
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Work $work)
{
$menu = Menu::where('link', 'work.index')->first();
abort_if(Gate::denies('update', $menu), 403, 'Unauthorized User');
Work::find($work->id)->update($request->all());
$response = [
"status" => 200,
"message" => "Data updated successfully"
];
return response()->json($response);
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\Work $work
* @return \Illuminate\Http\Response
*/
public function destroy(Work $work)
{
$menu = Menu::where('link', 'work.index')->first();
abort_if(Gate::denies('delete', $menu), 403, 'Unauthorized User');
Work::destroy($work->id);
$response = [
"status" => 200,
"message" => "Data deleted successfully"
];
return response()->json($response);
}
}