app/controllers/PostsController.php
/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
Store a newly created resource in storage.
@return Response
Store a newly created resource in storage . @return Response
public function store()
	{
		$validator = Validator::make(Input::all(), Post::$rules);
		if ($validator->fails())
		{
			Session::flash('errorMessage', 'Error: Missing Some Input');
			return Redirect::back()->withInput()->withErrors($validator);
		}
		else
		{
			Session::flash('successMessage', 'Success: New Post Added');
			$post = new Post();
			$post->user_id = Auth::user()->id;
			$post->title = Input::get('title');
			$post->body = Input::get('body');
			$post->slug = Input::get('title');
			$post->save();
			if (Input::hasFile('image') && Input::file('image')->isValid()){
				$post->addUploadImage(Input::file('image'));
				$post->save();
			}
			return Redirect::action('PostsController@show', $post->slug);
		}
	}
public function store ( ) { $ validator = Validator :: make ( Input :: all ( ) , Post :: $ rules ) ; if ( $ validator -> fails ( ) ) { Session :: flash ( 'errorMessage' , 'Error: Missing Some Input' ) ; return Redirect :: back ( ) -> withInput ( ) -> withErrors ( $ validator ) ; } else { Session :: flash ( 'successMessage' , 'Success: New Post Added' ) ; $ post = new Post ( ) ; $ post -> user_id = Auth :: user ( ) -> id ; $ post -> title = Input :: get ( 'title' ) ; $ post -> body = Input :: get ( 'body' ) ; $ post -> slug = Input :: get ( 'title' ) ; $ post -> save ( ) ; if ( Input :: hasFile ( 'image' ) && Input :: file ( 'image' ) -> isValid ( ) ) { $ post -> addUploadImage ( Input :: file ( 'image' ) ) ; $ post -> save ( ) ; } return Redirect :: action ( 'PostsController@show' , $ post -> slug ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .
// set flash data // set flash data