コード例 #1
0
 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
0
ファイル: PostRepository.php プロジェクト: lolzballs/website
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
ファイル: PostsController.php プロジェクト: vladzur/werken
 /**
  * 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
0
 /**
  * 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
0
ファイル: PostController.php プロジェクト: Yuth-Set/cms
 private function syncTags(Post $post, array $tags)
 {
     $post->tags()->sync($tags);
 }
コード例 #8
0
ファイル: PostController.php プロジェクト: AhmedMedo/Seo
 /**
  * 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
0
ファイル: PostsController.php プロジェクト: boxtar/laratest
 /**
  * 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
0
ファイル: AdminController.php プロジェクト: samizares/411jobs
 /**
  * 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));
 }