Advertisement
firmansmoh

ApiController.php

Dec 20th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.69 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Response;
  7. use App\Feedback;
  8.  
  9. class ApiController extends Controller
  10. {
  11.  
  12.     public function index() {
  13.         $data = Feedback::all();
  14.         $response = [
  15.             'msg' => 'data berhasil dimuat',
  16.             'data' => $data
  17.         ];
  18.         return response()->json($response,201) ;
  19.     }
  20.  
  21.     public function edit($id) {
  22.         $data = Feedback::find($id);
  23.         $response = [
  24.             'msg' => 'data enchant_broker_get_error(broker)hasil dimuat',
  25.             'data' => $data
  26.         ];
  27.         return response()->json($response,201) ;
  28.     }
  29.  
  30.  
  31.     public function store(Request $request)
  32.     {
  33.         Feedback::create([
  34.                 'nama' => $request->nama,
  35.                 'email' => $request->email,
  36.                 'feedback' => $request->feedback,
  37.         ]);
  38.  
  39.        
  40.         $response = [
  41.             'msg' => 'Data feedback terbuat',
  42.              'data' => $request->all()
  43.         ];
  44.  
  45.         return response()->json($response,201);    
  46.  
  47.     }
  48.  
  49.  
  50.     public function update(Request $request, $id)
  51.     {
  52.         $feed = Feedback::find($id);
  53.         $feed->update($request->all());
  54.  
  55.         $response = [
  56.             'msg' => 'data berhasil di update',
  57.             'data'=>  $request->all(),  
  58.         ];
  59.         return response()->json($response,201);
  60.     }
  61.  
  62.     public function destroy($id)
  63.     {
  64.         $feed = Feedback::find($id);
  65.  
  66.         $feed->delete();
  67.  
  68.          $response = [
  69.             'msg' => 'data berhasil di hapus',
  70.             'data'=>  $feed
  71.         ];
  72.  
  73.         return response()->json($response,201);
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement