app/Http/Controllers/NewsController.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(Request $request)
	{
		$validator = \Validator::make($request->all(), array(
			'title' => 'required',
			'text' => 'required'            
			));
		if ($validator->fails())
		{
			foreach ($validator->errors()->toArray() as $key => $value) {
				$error[]=$value[0];
			} 
		}
		else{
			if( session()->has('email')){
				$content['title']                 	= $request->title;
		        $content['reporter_email'] 			= session()->get('email');
		        $content['text']                   	= $request->text;
		        $file  								= $request->file('file');
		        $upload_obj 						= new UploadHandler();
				$content['image']                   = $upload_obj->upload($file);
		        $create_news = \App\News::create($content);
			 	return redirect()->route('home');
		 	}else
		 	{
		 		$error[] = "Session expired. Please login to continue";
		 	}
	 	}
	 	return redirect()->route('news', ['message' => $error])->withInput();
	}
public function store ( Request $ request ) { $ validator = \ Validator :: make ( $ request -> all ( ) , array ( 'title' => 'required' , 'text' => 'required' ) ) ; if ( $ validator -> fails ( ) ) { foreach ( $ validator -> errors ( ) -> toArray ( ) as $ key => $ value ) { $ error [ ] = $ value [ 0 ] ; } } else { if ( session ( ) -> has ( 'email' ) ) { $ content [ 'title' ] = $ request -> title ; $ content [ 'reporter_email' ] = session ( ) -> get ( 'email' ) ; $ content [ 'text' ] = $ request -> text ; $ file = $ request -> file ( 'file' ) ; $ upload_obj = new UploadHandler ( ) ; $ content [ 'image' ] = $ upload_obj -> upload ( $ file ) ; $ create_news = \ App \ News :: create ( $ content ) ; return redirect ( ) -> route ( 'home' ) ; } else { $ error [ ] = " Session expired. Please login to continue " ; } } return redirect ( ) -> route ( 'news' , [ 'message' => $ error ] ) -> withInput ( ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//Validations //Process when validations pass