Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reverse-update #243

Merged
merged 12 commits into from
Aug 4, 2022
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
</p>

<br>

## 📫 Join projek isengan ini?
Cek staging server https://cuyuniverse.co

Expand Down
15 changes: 15 additions & 0 deletions app/Http/Controllers/HashtagController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Http\Controllers;

use App\Http\Resources\PostsCollection;
use Illuminate\Http\Request;
use Inertia\Inertia;

class HashtagController extends Controller
{
public function index()
{
//
}
}
12 changes: 5 additions & 7 deletions app/Http/Controllers/OuterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function index(Request $request)
{
$posts = Posts::query()->with(['comments', 'users:id,image'])
->when($request->search, fn ($q, $key) => $q->where('description', 'like', "%{$key}%"))
->when($request->tag, fn ($q, $key) => $q->where('hashtag', '=', $key))
->when($request->filtered, function ($q, $value) {
switch ($value) {
case 'latest':
Expand All @@ -28,20 +29,17 @@ public function index(Request $request)
abort(404);
break;
}
})
->when($request->tag, fn ($q, $key) => $q->where('hashtag', '=', $key));

$trending = $posts->whereIn('hashtag', function ($query) {
$query->select('hashtag')->from('posts')->groupBy('hashtag')->havingRaw('count(*) > 1');
})->distinct()->limit(5)->get('hashtag');
});

return inertia('Posts', [
'title' => "CUY UNIVERSE",
'root' => 'HOME',
'description' => "Tempat Nongkrongnya Programmer Indie",
'posts' => PostResource::collection($posts->latest()->paginate(22)->withQueryString()),
'filter' => $request->only(['search', 'page', 'filtered', 'tag']),
'tags' => $trending,
'tags' => Posts::where('hashtag', '!=', null)->whereIn('hashtag', function ($query) {
$query->select('hashtag')->from('posts')->groupBy('hashtag')->havingRaw('count(*) > 10');
})->limit(5)->distinct()->get('hashtag')
]);
}

Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/Posts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default function PostsPage(props) {
<span className="py-1" key={i}>
<p
name="tag"
className={`${tag && 'bg-white text-black'} font-bold link px-2 hover:cursor-pointer hover:bg-white hover:text-black`}
className={`${tag == props.tags[i].hashtag && 'bg-white text-black'} font-bold link px-2 hover:cursor-pointer hover:bg-white hover:text-black`}
onClick={() => setTag(trend.hashtag)}>
#{trend.hashtag}
</p>
Expand Down