/**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (Post::find($request->id)->user_id !== Auth::user()->id || !$request->user()->hasRole('Admin')) {
         return redirect()->back();
     }
     return $next($request);
 }
 /**
  * Handle the event.
  *
  * @param  PostWasCreatedEvent  $event
  * @return void
  */
 public function handle(PostWasCreatedEvent $event)
 {
     $post = Post::find($event->post->id);
     $title = $post->title;
     $link = App::getLocale() . '/blog/post/' . $post->id;
     $user = User::find($event->user->id);
     $username = $user->name;
     $this->mailer->compose($user->email, $username, $title, $link)->send();
 }
Example #3
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $post = Post::find(Input::get('id'));
     if (!Auth::check()) {
         return redirect('home');
     } elseif (!$post || $post->user != Auth::id) {
         return redirect()->back();
     }
     return true;
 }
Example #4
0
 /**
  * list posts according to the tags
  *
  * @param $slug
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function tags($slug)
 {
     $posts = Post::withAnyTag([$slug])->latest('published_at')->published()->paginate(8);
     $countUserPosts = $this->repository->countUserPosts();
     return view('pages.blog', compact('posts', 'countUserPosts'));
 }