本文整理汇总了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'));
}
示例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);
}
示例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');
}
示例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);
}
示例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');
}
示例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');
}
示例7: syncTags
private function syncTags(Post $post, array $tags)
{
$post->tags()->sync($tags);
}
示例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');
}
示例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);
}
示例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));
}