示例#1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['news_title' => 'required', 'news_text' => 'required']);
     $news = new News();
     $news->is_published = $request->get('is_published') == 'on' ? 1 : 0;
     $news->title = $request->get('news_title');
     $news->text = $request->get('news_text');
     $news->save();
     if ($request->get('product_categories') != null) {
         foreach ($request->get('news_categories') as $category_id) {
             $news->categories()->attach($category_id);
         }
     }
     Session::flash('flash_message', 'Event successfully added!');
     return view('dashboard/create_news')->with('success', 1)->with('categories', Category::get())->with('news', new News());
 }