SHARE
TWEET

BiodataController

a guest Jan 28th, 2020 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use App\Biodata;
  6. use Illuminate\Http\Request;
  7.  
  8. class BiodataController extends Controller
  9. {
  10.     /**
  11.      * Display a listing of the resource.
  12.      *
  13.      * @return \Illuminate\Http\Response
  14.      */
  15.     public function index()
  16.     {
  17.         $biodata = Biodata::all();
  18.         return view('biodata.index', ['biodatas' => $biodata]);
  19.     }
  20.  
  21.     /**
  22.      * Show the form for creating a new resource.
  23.      *
  24.      * @return \Illuminate\Http\Response
  25.      */
  26.     public function create()
  27.     {
  28.         return view('biodata.create');
  29.     }
  30.  
  31.     /**
  32.      * Store a newly created resource in storage.
  33.      *
  34.      * @param  \Illuminate\Http\Request  $request
  35.      * @return \Illuminate\Http\Response
  36.      */
  37.     public function store(Request $request)
  38.     {
  39.  
  40.         // dd($request->all());
  41.  
  42.         Biodata::create([
  43.             'nama' => $request->nama,
  44.             'alamat' => $request->alamat,
  45.             'pekerjaan' => $request->pekerjaan,
  46.             'hobby' => $request->hobby,
  47.             'status'=> $request->status,
  48.         ]);
  49.         return redirect()->route('biodata.index');
  50.     }
  51.  
  52.     /**
  53.      * Display the specified resource.
  54.      *
  55.      * @param  \App\Biodata  $biodata
  56.      * @return \Illuminate\Http\Response
  57.      */
  58.     public function show(Biodata $biodata)
  59.     {
  60.         //
  61.     }
  62.  
  63.     /**
  64.      * Show the form for editing the specified resource.
  65.      *
  66.      * @param  \App\Biodata  $biodata
  67.      * @return \Illuminate\Http\Response
  68.      */
  69.     public function edit(Biodata $biodatum)
  70.     {
  71.         dd($biodatum);
  72.         return view('biodata.edit', ['biodatum' => $biodatum]);
  73.     }
  74.  
  75.     /**
  76.      * Update the specified resource in storage.
  77.      *
  78.      * @param  \Illuminate\Http\Request  $request
  79.      * @param  \App\Biodata  $biodata
  80.      * @return \Illuminate\Http\Response
  81.      */
  82.     public function update(Request $request, Biodata $biodata)
  83.     {
  84.         //
  85.         $request->validate([
  86.             'nama' => 'required',
  87.             'alamat' => 'required',
  88.             'pekerjaan' => 'required',
  89.             'hobby'=> 'required',
  90.             'status'=> 'required',
  91.         ]);
  92.         // dd($biodata);
  93.         $biodata->update([
  94.             'nama'=> $request->nama,
  95.             'alamat'=>$request->alamat,
  96.             'pekerjaan'=>$request->pekerjaan,
  97.             'hobby'=>$request->hobby,
  98.             'status'=>$request->status
  99.  
  100.         ]);
  101.  
  102.         return redirect()->route('biodata.index');
  103.     }
  104.  
  105.     /**
  106.      * Remove the specified resource from storage.
  107.      *
  108.      * @param  \App\Biodata  $biodata
  109.      * @return \Illuminate\Http\Response
  110.      */
  111.     public function destroy(Biodata $biodata)
  112.     {
  113.         //
  114.     }
  115. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top