Laraland/Modules/Karyawaf/Http/Controllers/KaryawanController.php
2018-07-30 09:26:17 +07:00

110 lines
2.4 KiB
PHP

<?php
namespace Modules\Karyawaf\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
use Modules\Karyawaf\Entities\Karyawan;
use Modules\Karyawaf\Http\Requests\StoreKaryawafKaryawan;
use Modules\Karyawaf\Http\Requests\UpdateKaryawafKaryawan;
class KaryawanController extends Controller
{
/**
* Display a listing of the resource.
* @return Response
*/
public function index()
{
$response = Karyawan::all();
return response()->json([
'data' => $response
]);
}
/**
* Show the form for creating a new resource.
* @return Response
*/
public function create()
{
return view('karyawaf::create');
}
/**
* Store a newly created resource in storage.
* @param StoreKaryawafKaryawan $request
* @return Response
*/
public function store(StoreKaryawafKaryawan $request)
{
$validated = $request->validated();
$response = Auth::user()->karyawans()->create($validated); // Auth::user()->karyawan->create()
return response()->json([
'data' => $response
]);
}
/**
* Show the specified resource.
* @param $id
* @return Response
*/
public function show($id)
{
$response = Karyawan::find($id);
return response()->json([
'data' => $response
]);
}
/**
* Show the form for editing the specified resource.
* @return Response
*/
public function edit()
{
return view('karyawaf::edit');
}
/**
* Update the specified resource in storage.
* @param UpdateKaryawafKaryawan $request
* @return Response
*/
public function update(UpdateKaryawafKaryawan $request, $id)
{
$karyawan = Karyawan::findOrFail($id);
$validated = $request->validated();
$karyawan->update($validated);
return response()->json([
'data' => $karyawan
]);
}
/**
* Remove the specified resource from storage.
* @param $id
* @return Response
*/
public function destroy($id)
{
$karyawan = Karyawan::findOrFail($id);
$karyawan->delete();
return response()->json([
'message' => 'The data has been deleted'
]);
}
}