46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Event;
|
|
use App\News;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
|
|
class RootController extends Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
$this->middleware("auth");
|
|
$this->middleware([ "lang" ]);
|
|
}
|
|
|
|
public function index() {
|
|
$perPage = 5;
|
|
|
|
$newsCollection = News::query()->orderBy('id', 'desc')->paginate($perPage);
|
|
|
|
foreach ($newsCollection as $new)
|
|
{
|
|
if($new->type_id == 3)
|
|
if(Event::query()->where('id', '=', $new->arrangement_id)->first() == null)
|
|
$new->delete();
|
|
}
|
|
|
|
if(auth()->user()->can('admin.panel.show')) {
|
|
if(Response::detect("root.index")->name() == "admin.root.index")
|
|
return view("admin.root.index");
|
|
else {
|
|
|
|
$news = News::query()->orderBy('id', 'desc')->paginate($perPage);
|
|
return view("app.root.index", ["news" => $news]);
|
|
}
|
|
}
|
|
else {
|
|
$news = News::query()->orderBy('id', 'desc')->paginate($perPage, ['*'], "page");
|
|
|
|
return Response::detect('root.index', ["news" => $news]);
|
|
}
|
|
}
|
|
}
|