160 lines
4.6 KiB
PHP
160 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Front;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Category;
|
|
use App\Models\RssPost;
|
|
use Artesaos\SEOTools\Facades\SEOTools;
|
|
use Illuminate\Http\Request;
|
|
use JsonLd\Context;
|
|
|
|
class FrontListController extends Controller
|
|
{
|
|
public function search(Request $request)
|
|
{
|
|
if (is_empty($request->input('query'))) {
|
|
return redirect()->back();
|
|
}
|
|
|
|
return redirect()->to(route('front.search.results',['query' => $request->input('query')]));
|
|
}
|
|
|
|
public function searchResults(Request $request, $query)
|
|
{
|
|
$page_type = 'search';
|
|
|
|
$query = strtolower($query);
|
|
|
|
$breadcrumbs = collect([
|
|
['name' => 'Home', 'url' => route('front.home')],
|
|
['name' => 'News Bites', 'url' => route('front.search.results',['query' => $query])],
|
|
['name' => $query, 'url' => null],
|
|
]);
|
|
|
|
$title = 'Latest News about '.ucwords($query).' in FutureWalker';
|
|
|
|
SEOTools::metatags();
|
|
SEOTools::twitter();
|
|
SEOTools::opengraph();
|
|
SEOTools::jsonLd();
|
|
SEOTools::setTitle($title, false);
|
|
|
|
$rss_posts = RssPost::with('category')
|
|
->where('status', 'published')
|
|
->whereRaw("to_tsvector('english', title || ' ' || bites || ' ' || body) @@ plainto_tsquery('english', ?)", [trim(preg_replace('/\s+/', ' ', $query))])
|
|
->where('published_at', '<=', now())
|
|
->orderBy('published_at', 'desc')
|
|
->cursorPaginate(60);
|
|
|
|
|
|
// breadcrumb json ld
|
|
$listItems = [];
|
|
|
|
foreach ($breadcrumbs as $index => $breadcrumb) {
|
|
$listItems[] = [
|
|
'name' => $breadcrumb['name'],
|
|
'url' => $breadcrumb['url'],
|
|
];
|
|
}
|
|
|
|
$breadcrumb_context = Context::create('breadcrumb_list', [
|
|
'itemListElement' => $listItems,
|
|
]);
|
|
|
|
return view('front.rss_post_list', compact('rss_posts', 'breadcrumbs', 'breadcrumb_context', 'title', 'page_type'));
|
|
}
|
|
|
|
public function index(Request $request)
|
|
{
|
|
$page_type = 'default';
|
|
|
|
$breadcrumbs = collect([
|
|
['name' => 'Home', 'url' => route('front.home')],
|
|
['name' => 'News Bites', 'url' => null], // or you can set a route for Latest News if there's a specific one
|
|
]);
|
|
|
|
$title = 'Latest News Bites from FutureWalker';
|
|
|
|
SEOTools::metatags();
|
|
SEOTools::twitter();
|
|
SEOTools::opengraph();
|
|
SEOTools::jsonLd();
|
|
SEOTools::setTitle($title, false);
|
|
|
|
$rss_posts = RssPost::with('category')->where('status', 'published')
|
|
->where('published_at', '<=', now())
|
|
->orderBy('published_at', 'desc')
|
|
->cursorPaginate(60) ?? collect();
|
|
|
|
// breadcrumb json ld
|
|
$listItems = [];
|
|
|
|
foreach ($breadcrumbs as $index => $breadcrumb) {
|
|
$listItems[] = [
|
|
'name' => $breadcrumb['name'],
|
|
'url' => $breadcrumb['url'],
|
|
];
|
|
}
|
|
|
|
//dd($rss_posts);
|
|
|
|
$breadcrumb_context = Context::create('breadcrumb_list', [
|
|
'itemListElement' => $listItems,
|
|
]);
|
|
|
|
return view('front.rss_post_list', compact('rss_posts', 'breadcrumbs', 'breadcrumb_context', 'page_type'));
|
|
}
|
|
|
|
public function category(Request $request, $category_slug)
|
|
{
|
|
$page_type = 'category';
|
|
|
|
$category = Category::where('slug', $category_slug)->first();
|
|
|
|
if (is_null($category))
|
|
{
|
|
abort(404);
|
|
}
|
|
|
|
|
|
$breadcrumbs = collect([
|
|
['name' => 'Home', 'url' => route('front.home')],
|
|
['name' => $category->name, 'url' => null],
|
|
]);
|
|
|
|
$title = 'Latest News from FutureWalker';
|
|
|
|
|
|
SEOTools::metatags();
|
|
SEOTools::twitter();
|
|
SEOTools::opengraph();
|
|
SEOTools::jsonLd();
|
|
SEOTools::setTitle($title, false);
|
|
|
|
$rss_posts = RssPost::with('category')->where('status', 'published')
|
|
->where('category_id', $category->id)
|
|
->where('published_at', '<=', now())
|
|
->orderBy('published_at', 'desc')
|
|
->cursorPaginate(60) ?? collect();
|
|
|
|
// breadcrumb json ld
|
|
$listItems = [];
|
|
|
|
foreach ($breadcrumbs as $index => $breadcrumb) {
|
|
$listItems[] = [
|
|
'name' => $breadcrumb['name'],
|
|
'url' => $breadcrumb['url'],
|
|
];
|
|
}
|
|
|
|
//dd($rss_posts);
|
|
|
|
$breadcrumb_context = Context::create('breadcrumb_list', [
|
|
'itemListElement' => $listItems,
|
|
]);
|
|
|
|
return view('front.rss_post_list', compact('rss_posts', 'breadcrumbs', 'breadcrumb_context', 'page_type','category'));
|
|
}
|
|
}
|