public function delete($id)
 {
     $article = Article::findOrFail($id);
     if (Gate::denies('manage-article', $article)) {
         return abort('403');
     }
     $article->delete();
     $this->flasher->success('Post Deleted', 'That post has been permanently removed');
     return redirect('admin/blog');
 }
예제 #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('tags')->truncate();
     DB::table('taggables')->truncate();
     factory(App\Associations\Tag::class, 10)->create();
     foreach (Article::all() as $article) {
         $article->tags()->sync([rand(1, 10), rand(1, 10), rand(1, 10)]);
     }
     DB::table('images')->truncate();
     DB::table('imagables')->truncate();
     factory(App\Associations\Image::class, 10)->create();
     foreach (Article::all() as $article) {
         $article->images()->sync([rand(1, 10), rand(1, 10), rand(1, 10)]);
     }
     DB::table('favourites')->truncate();
     foreach (User::all() as $user) {
         $article = Article::find(rand(1, 10));
         $article2 = Article::find(rand(1, 10));
         Favourite::create(['user_id' => $user->id, 'favourable_id' => $article->id, 'favourable_type' => get_class($article)]);
         Favourite::create(['user_id' => $user->id, 'favourable_id' => $article2->id, 'favourable_type' => get_class($article2)]);
         // @todo: favourite a Product or two here
     }
 }
 public function show($slug)
 {
     $article = Article::where('slug', $slug)->firstOrFail();
     return view('front.blog.show')->with(compact('article'));
 }
예제 #4
0
 public function findBySlugWithArticlesPaginated($slug, $limit = 5)
 {
     $category = $this->category->where('slug', $slug)->first();
     $articles = Article::with('author')->where('category_id', $category->id)->paginate($limit);
     return collect(['category' => $category, 'articles' => $articles]);
 }
예제 #5
0
 /**
  * @test
  */
 public function an_article_can_have_an_image_assosiated_to_it()
 {
     $this->withoutMiddleware();
     $this->asAnAdminUser();
     $article = factory(\App\Blog\Article::class)->create();
     $response = $this->call('POST', '/admin/uploads/blog/' . $article->id . '/image', [], [], ['file' => $this->prepareFileUpload(realpath('tests/testpic1.png'))]);
     $this->assertEquals(200, $response->status());
     $article = \App\Blog\Article::findOrFail($article->id);
     $this->assertContains('/media', $article->coverPic(), 'has a media image');
     $article->clearMediaCollection();
 }
 protected function getArticles()
 {
     return Cache::remember('home:articles', static::CACHE_DURATION, function () {
         return Article::with('author')->where('published', 1)->latest()->take(3)->get();
     });
 }