junafandi

controller

May 20th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.00 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\DB;
  7.  
  8.  
  9. use App\blog;
  10.  
  11. class BlogController extends Controller
  12. {
  13.     public function index()
  14.     {
  15.         //insert biasa
  16.         // $blog  = new blog;
  17.         // $blog->judul = 'kucing';
  18.         // $blog->isi = 'Kucing adalah sejenis hewan mamalia';
  19.         // $blog->save();
  20.  
  21.         // blog::create([
  22.         //      'judul' => 'kambing',
  23.         //      'isi'   => 'kambing adalah jenis mamalia herbivora'
  24.         //  ]);
  25.  
  26.         $tab = blog::all();
  27.  
  28.         return view ('home', ['tab' => $tab]);
  29.     }
  30.  
  31.     public function show($id)
  32.     {
  33.  
  34.         $tab = blog::find($id);
  35.        
  36.  
  37.         // DB::table('user')->insert([
  38.         //      ['nama' => 'andi', 'pw' => '978']
  39.         //  ]);
  40.         $nama = DB::table('user')->get();  
  41.         $nilai = 'ini adalah linknya '.$id;
  42.         $users = ['anggi' , ' irki' , 'sanari' , 'jun'];
  43.         $jumlah = 10*10;
  44.         return view('satu', ['blog' => $nilai,
  45.                              'users' => $users,
  46.                              'jumlah' => $jumlah,
  47.                              'nama' => $nama,
  48.                              'tab' => $tab
  49.                              ]);
  50.     }
  51.  
  52.  
  53.     public function create()
  54.     {
  55.  
  56.  
  57.         return view('create');
  58.  
  59.     }
  60.  
  61.      public function store(Request $request)
  62.     {
  63.  
  64.          // dd($request);
  65.         //validation
  66.         $this->validate($request,[
  67.  
  68.             'judul' => 'required|email'
  69.             ]);
  70.  
  71.         // insert biasa
  72.         $blog  = new blog;
  73.         $blog->judul = $request->judul;
  74.         $blog->isi = $request->isi;
  75.         $blog->save();
  76.  
  77.  
  78.  
  79.         return redirect('blog');
  80.     }
  81.  
  82.  
  83.  
  84.  
  85.  
  86.     public function edit($id)
  87.     {
  88.         $tab = blog::find($id);
  89.  
  90.         return view('edit',['tab' => $tab]);
  91.  
  92.     }
  93.  
  94.     public function update(Request $request,$id)
  95.     {
  96.  
  97.         blog::find($id)->update([
  98.             'judul'     => $request->judul,
  99.             'isi'       => $request->isi,
  100.         ]);
  101.         dd('sukses');
  102.     }
  103.  
  104.     public function destroy($id)
  105.     {
  106.         $blog = blog::find($id);
  107.         $blog->delete();
  108.  
  109.         return redirect('blog');
  110.     }
  111. }
Add Comment
Please, Sign In to add comment