5
5
namespace App \Http \Controllers ;
6
6
7
7
use App \Models \Article ;
8
- use App \Models \User ;
9
8
use App \Policies \ArticlePolicy ;
10
9
use Illuminate \Contracts \View \View ;
11
- use Illuminate \Support \Facades \Auth ;
12
- use Illuminate \Support \Facades \Cache ;
13
10
14
11
final class ArticlesController extends Controller
15
12
{
@@ -18,43 +15,6 @@ public function __construct()
18
15
$ this ->middleware (['auth ' , 'verified ' ], ['except ' => ['index ' , 'show ' ]]);
19
16
}
20
17
21
- public function index (): View
22
- {
23
- return view ('articles.index ' );
24
- }
25
-
26
- public function show (Article $ article ): View
27
- {
28
- /** @var User $user */
29
- $ user = Auth::user ();
30
-
31
- views ($ article )->record ();
32
-
33
- /** @var Article $article */
34
- $ article = Cache::remember ('post- ' .$ article ->id , now ()->addHour (), fn () => $ article );
35
-
36
- abort_unless (
37
- $ article ->isPublished () || ($ user && $ article ->isAuthoredBy ($ user )) || ($ user && $ user ->hasAnyRole (['admin ' , 'moderator ' ])), // @phpstan-ignore-line
38
- 404
39
- );
40
-
41
- $ image = $ article ->getFirstMediaUrl ('media ' );
42
- // @phpstan-ignore-next-line
43
- seo ()
44
- ->title ($ article ->title )
45
- ->description ($ article ->excerpt (100 ))
46
- ->image ($ image )
47
- ->twitterTitle ($ article ->title )
48
- ->twitterDescription ($ article ->excerpt (100 ))
49
- ->twitterImage ($ image )
50
- ->twitterSite ('laravelcm ' )
51
- ->withUrl ();
52
-
53
- return view ('articles.show ' , [
54
- 'article ' => $ article ->loadCount ('views ' ),
55
- ]);
56
- }
57
-
58
18
public function create (): View
59
19
{
60
20
return view ('articles.new ' );
0 commit comments