2020-06-08 13:08:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-08-31 11:20:49 +00:00
|
|
|
use App\Event;
|
2020-08-19 07:54:26 +00:00
|
|
|
use App\News;
|
2020-06-08 13:08:46 +00:00
|
|
|
use Illuminate\Http\Request;
|
2020-06-24 06:23:15 +00:00
|
|
|
use Illuminate\Http\Response;
|
2020-06-08 13:08:46 +00:00
|
|
|
|
|
|
|
class RootController extends Controller
|
|
|
|
{
|
2020-06-30 08:42:10 +00:00
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware("auth");
|
2020-08-06 13:31:38 +00:00
|
|
|
$this->middleware([ "lang" ]);
|
2020-06-30 08:42:10 +00:00
|
|
|
}
|
|
|
|
|
2020-06-08 13:08:46 +00:00
|
|
|
public function index() {
|
2020-08-25 12:07:20 +00:00
|
|
|
$perPage = 5;
|
2020-08-19 07:54:26 +00:00
|
|
|
|
2020-08-31 11:20:49 +00:00
|
|
|
$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();
|
|
|
|
}
|
|
|
|
|
2020-08-19 07:54:26 +00:00
|
|
|
if(auth()->user()->can('admin.panel.show')) {
|
|
|
|
if(Response::detect("root.index")->name() == "admin.root.index")
|
2020-08-27 11:59:11 +00:00
|
|
|
return view("admin.root.index");
|
2020-08-19 07:54:26 +00:00
|
|
|
else {
|
2020-08-31 11:20:49 +00:00
|
|
|
|
2020-08-31 12:31:56 +00:00
|
|
|
$news = News::query()->join('news_types', 'news_types.id', '=', 'news.type_id')->orderBy('id', 'desc')->paginate($perPage);
|
2020-08-27 11:59:11 +00:00
|
|
|
return view("app.root.index", ["news" => $news]);
|
2020-08-19 07:54:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2020-08-31 12:31:56 +00:00
|
|
|
$news = News::query()->join('news_types', 'news_types.id', '=', 'news.type_id')->orderBy('id', 'desc')->paginate($perPage, ['*'], "page");
|
2020-08-19 07:54:26 +00:00
|
|
|
|
2020-08-27 11:59:11 +00:00
|
|
|
return Response::detect('root.index', ["news" => $news]);
|
2020-08-19 07:54:26 +00:00
|
|
|
}
|
2020-06-08 13:08:46 +00:00
|
|
|
}
|
|
|
|
}
|