34 lines
924 B
PHP
34 lines
924 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use App\Article;
|
|
|
|
class NameSpaceController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
return view('namespaces.index');
|
|
}
|
|
|
|
public function show($namespace)
|
|
{
|
|
if (!array_key_exists($namespace, config('karudhaas.topic_filters'))) return redirect('/namespaces');
|
|
|
|
$options = config("karudhaas.topic_filters." . $namespace);
|
|
|
|
$articles = Cache::remember("articles.$namespace", 600, function () use ($options) {
|
|
return Article::with('source')->whereHas('topics', function ($q) use ($options) {
|
|
$q->whereIn('slug', $options["keys"]);
|
|
})->latest('published_date')->limit(8)->get();
|
|
});
|
|
|
|
return view('namespaces.show', [
|
|
'options' => $options,
|
|
'articles' => $articles
|
|
]);
|
|
}
|
|
}
|