|
@@ -3,6 +3,7 @@
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
use App\Post;
|
|
|
+use Carbon\Carbon;
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
class PostsController extends Controller
|
|
@@ -53,11 +54,24 @@ class PostsController extends Controller
|
|
|
*
|
|
|
* @return \Illuminate\Http\Response
|
|
|
*/
|
|
|
- public function index()
|
|
|
+ public function index(Request $request)
|
|
|
{
|
|
|
-
|
|
|
- $posts = Post::latest()->get();
|
|
|
- return view('posts.index', compact('posts'));
|
|
|
+ $posts = Post::latest()
|
|
|
+ ->filter($request->only(['month', 'year']))
|
|
|
+ ->get();
|
|
|
+
|
|
|
+
|
|
|
+ $archives = Post::selectRaw(<<<EOT
|
|
|
+year(created_at) as year,
|
|
|
+monthname(created_at) as month,
|
|
|
+count(*) published
|
|
|
+EOT
|
|
|
+ )->groupBy('year', 'month')
|
|
|
+ ->orderByRaw('min(created_at) desc')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ return view('posts.index', compact('archives', 'posts'));
|
|
|
}
|
|
|
|
|
|
public function show(Post $post)
|