json([ // 'data' => $response // ]); return responder() ->success(Karyawan::all()) ->meta(['count' => Karyawan::count()]) ->respond(); } /** * 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 // ]); return responder() ->success($response) ->respond(); } /** * Show the specified resource. * @param $id * @return Response */ public function show($id) { $response = Karyawan::find($id); // return response()->json([ // 'data' => $response // ]); if (!$response) { return responder() ->error('karyawan_error', 'Cannot find `karyawan` with id ' . $id) ->respond(); } return responder() ->success($response) ->respond(); } /** * 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 // ]); return responder() ->success($karyawan) ->respond(); } /** * 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' // ]); return responder() ->success(['message' => 'The data has been deleted']) ->respond(); } }