Ejemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  * POST /admin\article
  *
  * @return Response
  */
 public function store()
 {
     try {
         $rules = array('title' => 'required|unique:articles', 'content' => 'required', 'author' => 'required');
         $validation = Validator::make(Input::all(), $rules);
         if ($validation->fails()) {
             return Redirect::back()->withInput()->withErrors($validation->messages());
         }
         $article = new Article();
         $article->title = Input::get('title');
         $article->author_id = Input::get('author');
         $article->content = Input::get('content');
         $article->shows = Input::get('shows') ? true : false;
         $article->gallery_id = is_numeric(Input::get('gallery')) ? Input::get('gallery') : 0;
         if ($article->save()) {
             if (Input::get('tags')) {
                 $article->tag(explode(',', Input::get('tags')));
             }
             return Redirect::back()->with('message', 'A hír feltöltése sikerült!');
         } else {
             return Redirect::back()->withInput()->withErrors('A hír feltöltése nem sikerült!');
         }
     } catch (Exception $e) {
         if (Config::get('app.debug')) {
             return Redirect::back()->withInput()->withErrors($e->getMessage());
         } else {
             return Redirect::back()->withInput()->withErrors('A hír feltöltése nem sikerült!');
         }
     }
 }