SHARE
TWEET

ArticlesController.php

a guest Sep 18th, 2019 91 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\Article;
  6. use Illuminate\Http\Request;
  7.  
  8. class ArticlesController extends Controller
  9. {
  10.     /**
  11.      * Display a listing of the resource.
  12.      *
  13.      * @return \Illuminate\Http\Response
  14.      */
  15.     public function index()
  16.     {
  17.         $articles = article::all();
  18.         return view("posts")-with("articles", $articles);
  19.        // return $articles;
  20.         //
  21.     }
  22.  
  23.     /**
  24.      * Show the form for creating a new resource.
  25.      *
  26.      * @return \Illuminate\Http\Response
  27.      */
  28.     public function create()
  29.     {
  30.         //
  31.         return view('posts.create');
  32.     }
  33.  
  34.     /**
  35.      * Store a newly created resource in storage.
  36.      *
  37.      * @param  \Illuminate\Http\Request  $request
  38.      * @return \Illuminate\Http\Response
  39.      */
  40.     public function store(Request $request)
  41.     {
  42.         //
  43.           // Validate data
  44.         $this->validate($request, array(
  45.             'title' => 'required | max:100',
  46.             'content' => 'required',
  47.             'link'  => 'required'
  48.         ));
  49.  
  50.         //store in the database
  51.         $post = new Article;
  52.  
  53.         $post->title = $request->title;
  54.         $post->content = $request->content;
  55.         $post->link = $request->link;
  56.  
  57.         $post->save();
  58.  
  59.         return redirect()->route('posts.show', $post->id);
  60.  
  61.     }
  62.  
  63.     /**
  64.      * Display the specified resource.
  65.      *
  66.      * @param  \App\articles  $articles
  67.      * @return \Illuminate\Http\Response
  68.      */
  69.     public function show(articles $articles)
  70.     {
  71.         //
  72.     }
  73.  
  74.     /**
  75.      * Show the form for editing the specified resource.
  76.      *
  77.      * @param  \App\articles  $articles
  78.      * @return \Illuminate\Http\Response
  79.      */
  80.     public function edit(articles $articles)
  81.     {
  82.         //
  83.     }
  84.  
  85.     /**
  86.      * Update the specified resource in storage.
  87.      *
  88.      * @param  \Illuminate\Http\Request  $request
  89.      * @param  \App\articles  $articles
  90.      * @return \Illuminate\Http\Response
  91.      */
  92.     public function update(Request $request, articles $articles)
  93.     {
  94.         //
  95.     }
  96.  
  97.     /**
  98.      * Remove the specified resource from storage.
  99.      *
  100.      * @param  \App\articles  $articles
  101.      * @return \Illuminate\Http\Response
  102.      */
  103.     public function destroy(articles $articles)
  104.     {
  105.         //
  106.     }
  107. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top