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')); }
/** * 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); }
/** * 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'); }
/** * 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); }
/** * 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'); }
/** * 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'); }
private function syncTags(Post $post, array $tags) { $post->tags()->sync($tags); }
/** * 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'); }
/** * 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); }
/** * 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)); }