本文整理汇总了PHP中app\News::categories方法的典型用法代码示例。如果您正苦于以下问题:PHP News::categories方法的具体用法?PHP News::categories怎么用?PHP News::categories使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\News
的用法示例。
在下文中一共展示了News::categories方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* 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());
}