2020-03-29 01:03:52 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Composers;
|
|
|
|
|
|
|
|
use App\Contracts\Composer;
|
|
|
|
use App\Repositories\PageRepository;
|
2020-03-29 07:07:46 +08:00
|
|
|
use Exception;
|
2020-03-29 01:03:52 +08:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Illuminate\View\View;
|
|
|
|
|
|
|
|
class PageLinksComposer extends Composer
|
|
|
|
{
|
|
|
|
protected $pageRepo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PageLinksComposer constructor.
|
|
|
|
*
|
|
|
|
* @param \App\Repositories\PageRepository $pageRepo
|
|
|
|
*/
|
|
|
|
public function __construct(PageRepository $pageRepo)
|
|
|
|
{
|
|
|
|
$this->pageRepo = $pageRepo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \Illuminate\View\View $view
|
|
|
|
*/
|
|
|
|
public function compose(View $view)
|
|
|
|
{
|
2020-03-29 07:07:46 +08:00
|
|
|
try {
|
2020-06-06 00:49:22 +08:00
|
|
|
$w = [
|
|
|
|
'enabled' => true,
|
|
|
|
];
|
|
|
|
|
2020-03-29 07:07:46 +08:00
|
|
|
// If not logged in, then only get the public pages
|
|
|
|
if (!Auth::check()) {
|
2020-06-06 00:49:22 +08:00
|
|
|
$w['public'] = true;
|
2020-03-29 07:07:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$pages = $this->pageRepo->findWhere($w, ['id', 'name', 'slug', 'icon']);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$pages = [];
|
2020-03-29 01:03:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$view->with('page_links', $pages);
|
|
|
|
}
|
|
|
|
}
|