當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Post::categories方法代碼示例

本文整理匯總了PHP中app\Post::categories方法的典型用法代碼示例。如果您正苦於以下問題:PHP Post::categories方法的具體用法?PHP Post::categories怎麽用?PHP Post::categories使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\Post的用法示例。


在下文中一共展示了Post::categories方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: store

 public function store(PostFormRequest $request)
 {
     $post = new Post(['title' => $request->get('title'), 'content' => $request->get('content'), 'slug' => Str::slug($request->get('title'), '-')]);
     $post->save();
     $post->categories()->sync($request->get('categories'));
     return redirect('/admin/posts/create')->with('status', 'The post has been created!');
 }
開發者ID:corean,項目名稱:LearningLaravel,代碼行數:7,代碼來源:PostsController.php

示例2: removeCategory

 /**
  * Remove given category from given post.
  *
  * @param Post $post
  * @param Category $category
  * @return void
  * @throws NotFoundHttpException
  */
 public function removeCategory(Post $post, Category $category)
 {
     if (!$post->categories->contains($category->id)) {
         throw new NotFoundHttpException("Category doesn't exist on Post #" . $post->id);
     }
     $post->categories()->detach($category->id);
 }
開發者ID:lolzballs,項目名稱:website,代碼行數:15,代碼來源:PostRepository.php

示例3: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //handel the request
     $validator = Validator::make($request->all(), ['title' => 'required|unique:posts|max:67', 'image' => 'required|image|mimes:jpeg,png|max:5000']);
     if ($validator->fails()) {
         return redirect('seodashboard/posts/create')->withErrors($validator)->withInput();
     }
     $post = new Post();
     $post->title = $request->input('title');
     $post->content = $request->input('content');
     $post->published = $request->input('status');
     $post->excrypt = str_limit($request->input('excrypt'), 155);
     $tags = $request->input('tags');
     $categories = $request->input('categories');
     $tags = $this->ConvertTagsToList($tags);
     //save image path in database
     if ($request->hasFile('image')) {
         $destinationPath = 'images';
         $file = $request->file('image');
         $fileName = $file->getClientOriginalName();
         $file->move($destinationPath, $fileName);
         $post->image = $fileName;
     }
     $post->save();
     $post->tags()->attach($tags);
     $post->categories()->attach($categories);
     return redirect('seodashboard/posts');
 }
開發者ID:AhmedMedo,項目名稱:Seo,代碼行數:34,代碼來源:PostController.php


注:本文中的app\Post::categories方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。