当前位置: 首页>>代码示例>>PHP>>正文


PHP Post::tags方法代码示例

本文整理汇总了PHP中app\Post::tags方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::tags方法的具体用法?PHP Post::tags怎么用?PHP Post::tags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Post的用法示例。


在下文中一共展示了Post::tags方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: update

 public function update(PostRequest $request, Post $post)
 {
     if ($post->user()->getResults() != Auth::user()) {
         return response('Unauthorized.', 401);
     }
     $post->update($request->all());
     $post->tags()->detach();
     $post->tags()->attach($request->input('tags'));
     return view('posts.show', compact('post'));
 }
开发者ID:khaled-barca,项目名称:MyTunnelVision,代码行数:10,代码来源:PostController.php

示例2: removeTag

 /**
  * Add given tag to given post.
  *
  * @param Post $post
  * @param Tag $tag
  * @return void
  * @throws NotFoundHttpException
  */
 public function removeTag(Post $post, Tag $tag)
 {
     if (!$post->tags->contains($tag->id)) {
         throw new NotFoundHttpException("Tag doesn't exist on Post #" . $post->id);
     }
     $post->tags()->detach($tag->id);
 }
开发者ID:lolzballs,项目名称:website,代码行数:15,代码来源:PostRepository.php

示例3: update

 /**
  * PUT admin/posts/{post}
  *
  * @param Post        $post
  * @param PostRequest $request
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function update(Post $post, PostRequest $request)
 {
     $post->update($request->all());
     if ($request->has('tag_list')) {
         $post->tags()->sync(Tag::findOrCreateMany($request->get('tag_list')));
     }
     flash()->success('The post has been updated');
     return redirect('/admin/posts');
 }
开发者ID:spitzgoby,项目名称:spitzgoby,代码行数:16,代码来源:PostsController.php

示例4: handle

 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     //Creating post with all post data
     $post = new Post($this->post);
     //Associating one post with one user
     // Post->belongsTo User-> associate
     $post->user()->associate($this->user);
     $post->save();
     //Attaching tags
     $post->tags()->attach($this->tags);
 }
开发者ID:robertzibert,项目名称:learning_laravel_5.1,代码行数:16,代码来源:PublishPost.php

示例5: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $post = new Post();
     $post->fill($request->all());
     $post->user_id = Auth::user()->id;
     $post->slug = str_slug($post->title);
     $post->draft = !empty($request->draft);
     $post->save();
     $tags = explode(',', $request->tags);
     foreach ($tags as $tag) {
         $tag_ids[] = Tag::getId($tag);
     }
     $post->tags()->sync($tag_ids);
     return redirect('admin/posts');
 }
开发者ID:vladzur,项目名称:werken,代码行数:21,代码来源:PostsController.php

示例6: update

 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  Post  $post
  * @return Response
  */
 public function update(Post $post, PostRequest $request)
 {
     $post->update($request->all());
     $post->tags()->sync($request->input('tag_list', []));
     $post->slug = str_slug($post->title, "-");
     $post->save();
     return redirect('posts/postsAuth');
 }
开发者ID:grigoremihaela,项目名称:myfirstlaravel,代码行数:15,代码来源:PostsController.php

示例7: syncTags

 private function syncTags(Post $post, array $tags)
 {
     $post->tags()->sync($tags);
 }
开发者ID:Yuth-Set,项目名称:cms,代码行数:4,代码来源:PostController.php

示例8: 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

示例9: sync_tags

 /**
  * Keep tags associated with post in sync
  *
  * @param Post $post
  * @param array $tags
  */
 private function sync_tags(Post $post, $tags)
 {
     $post->tags()->sync((array) $tags);
 }
开发者ID:boxtar,项目名称:laratest,代码行数:10,代码来源:PostsController.php

示例10: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(PostCreateRequest $request)
 {
     //dd(\Input::all());
     $post = new Post();
     $post->title = $request->get('title');
     $post->company_name = $request->get('company');
     $date = $request->get('closing');
     //dd(date('Y-m-d', strtotime($date)));
     $post->closing = date('Y-m-d', strtotime($date));
     $post->job_description = $request->get('job_description');
     $post->job_experience = $request->get('job_experience');
     $post->company_description = $request->get('company_description');
     $post->salary = $request->get('salary');
     $publish = $request->get('publish');
     $save = $request->get('save');
     $state = $request->get('location');
     $cat = $request->get('category');
     $tags = $request->get('tags');
     $tagNames = [];
     foreach ($tags as $tag) {
         if ($existingTag = Tag::where('name', $tag)->first()) {
             $TagNames[] = $existingTag;
         } else {
             $newTag = new Tag();
             $newTag->name = $tag;
             $newTag->save();
             $TagNames[] = $newTag;
         }
     }
     if (isset($publish)) {
         $post->active = 1;
         $post->save();
         $post->tags()->saveMany($TagNames);
         $newCat = new Category();
         $newCat->name = $cat;
         $newCat->post_id = $post->id;
         $newCat->save();
         // $post->tags()->sync($tag);
         $sta = new State();
         $sta->name = $state;
         $sta->post_id = $post->id;
         $sta->save();
         return redirect('admin')->withSuccess("New job has been published");
     } else {
         if (isset($save)) {
             $post->active = 0;
             $post->save();
             $post->tags()->saveMany($TagNames);
             $newCat = new Category();
             $newCat->name = $cat;
             $newCat->post_id = $post->id;
             $newCat->save();
             // $post->tags()->sync($tag);
             $sta = new State();
             $sta->name = $state;
             $sta->post_id = $post->id;
             $sta->save();
             return redirect('/admin')->withErrors("The post has been saved for publishing later");
         }
     }
     // dd(strip_tags($raw));
 }
开发者ID:samizares,项目名称:411jobs,代码行数:68,代码来源:AdminController.php


注:本文中的app\Post::tags方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。