/**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     try {
         $post_tag = new Post();
         $post_tag->title = $request->input('title');
         $post_tag->body = $request->input('body');
         $post_tag->save();
         return response()->json(array('error' => false, 'message' => 'Post tag added successfully.'), 200);
     } catch (Exception $e) {
         throw $e;
     }
 }
Пример #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $user = Auth::user();
     // Rules that validator will check. Required will prompt the user if the content is left empty.
     $rules = array('name', 'title' => 'required', 'content' => 'required');
     //Sets the validator to grab all of the input data from the create.blade.php view and then checks it agains the rules that were previously set.
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to('post/create')->withErrors($validator)->withInput(Input::all());
     } else {
         $post = new Post();
         $post->name = Input::get('name');
         $post->title = Input::get('title');
         $post->content = Input::get('content');
         $post->user_id = $user->id;
         $post->save();
         return Redirect::to('post');
     }
 }