2017-06-11 09:27:24 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
2018-01-09 06:22:26 +08:00
|
|
|
use Auth;
|
2017-06-11 09:27:24 +08:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
2018-01-09 06:22:26 +08:00
|
|
|
use App\Repositories\NewsRepository;
|
2017-12-23 04:48:15 +08:00
|
|
|
use App\Repositories\PirepRepository;
|
|
|
|
use App\Repositories\UserRepository;
|
|
|
|
|
2017-06-11 11:17:45 +08:00
|
|
|
class DashboardController extends BaseController
|
2017-06-11 09:27:24 +08:00
|
|
|
{
|
2018-01-09 06:22:26 +08:00
|
|
|
private $newsRepo, $pirepRepo, $userRepo;
|
2017-12-04 00:55:01 +08:00
|
|
|
|
|
|
|
public function __construct(
|
2018-01-09 06:22:26 +08:00
|
|
|
NewsRepository $newsRepo,
|
2017-12-23 04:48:15 +08:00
|
|
|
PirepRepository $pirepRepo,
|
|
|
|
UserRepository $userRepo
|
2017-12-04 00:55:01 +08:00
|
|
|
) {
|
2018-01-09 06:22:26 +08:00
|
|
|
$this->newsRepo = $newsRepo;
|
2017-12-04 00:55:01 +08:00
|
|
|
$this->pirepRepo = $pirepRepo;
|
2017-12-23 04:48:15 +08:00
|
|
|
$this->userRepo = $userRepo;
|
2017-12-04 00:55:01 +08:00
|
|
|
}
|
|
|
|
|
2017-06-11 09:27:24 +08:00
|
|
|
/**
|
|
|
|
* Display a listing of the Airlines.
|
|
|
|
*/
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
2017-08-19 01:02:32 +08:00
|
|
|
return view('admin.dashboard.index', [
|
2018-01-09 06:22:26 +08:00
|
|
|
'news' => $this->newsRepo->getLatest(),
|
2017-12-04 00:55:01 +08:00
|
|
|
'pending_pireps' => $this->pirepRepo->getPendingCount(),
|
2017-12-23 04:48:15 +08:00
|
|
|
'pending_users' => $this->userRepo->getPendingCount(),
|
2017-07-23 10:31:26 +08:00
|
|
|
]);
|
2017-06-11 09:27:24 +08:00
|
|
|
}
|
2018-01-09 06:22:26 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Request $request
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
|
|
|
*/
|
|
|
|
public function news(Request $request)
|
|
|
|
{
|
|
|
|
if($request->isMethod('post')) {
|
|
|
|
$attrs = $request->post();
|
|
|
|
$attrs['user_id'] = Auth::user()->id;
|
|
|
|
|
2018-01-09 06:35:52 +08:00
|
|
|
$this->newsRepo->create($attrs);
|
2018-01-09 06:22:26 +08:00
|
|
|
} elseif ($request->isMethod('delete')) {
|
|
|
|
$news_id = $request->input('news_id');
|
|
|
|
$this->newsRepo->delete($news_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('admin.dashboard.news', [
|
|
|
|
'news' => $this->newsRepo->getLatest(),
|
|
|
|
]);
|
|
|
|
}
|
2017-06-11 09:27:24 +08:00
|
|
|
}
|