-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostController.php
52 lines (43 loc) · 1.13 KB
/
PostController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace App\Http\Controllers\Frontend;
use App\Http\Controllers\Controller;
use App\Models\Post;
use App\Repository\Post\PostRepositoryInterface;
use Illuminate\Http\Request;
use Illuminate\View\View;
class PostController extends Controller
{
private $postRepository;
/**
* PostController constructor.
* @param PostRepositoryInterface $postRepository
* PostController constructor.
* Just to demonstrate, here I used repository pattern
*/
public function __construct(PostRepositoryInterface $postRepository)
{
$this->postRepository = $postRepository;
}
/**
* Display a listing of the resource.
* @param Request $request
* @return View
*/
public function index(Request $request) : View
{
return view('posts.index', [
'posts' => $this->postRepository->all($request->sort, $request->q)
]);
}
/**
* Display the specified resource.
* @param Post $post
* @return View
*/
public function show(Post $post) : View
{
return view('posts.show', [
'post' => $post
]);
}
}