college-courses/app/View/Components/Header/Navbar.php

56 lines
1.2 KiB
PHP

<?php
namespace App\View\Components\Header;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
use Illuminate\View\Component;
class Navbar extends Component
{
public $routes = [
[
'title' => 'Главная',
'link' => '/',
],
];
protected $authRoutes = [
[
'title' => 'Каталог',
'link' => '/catalog',
]
];
protected $manageRoutes = [
[
'title' => 'Управление курсами',
'link' => '/manage/course',
]
];
/**
* Create a new component instance.
*/
public function __construct()
{
//
if (Auth::check()) {
$this->routes = array_merge($this->routes, $this->authRoutes);
};
if (Gate::allows('course-create')) {
$this->routes = array_merge($this->routes, $this->manageRoutes);
};
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.header.navbar', ['routes' => $this->routes]);
}
}