当前位置: 首页>>代码示例>>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;未经允许,请勿转载。