Package Data | |
---|---|
Maintainer Username: | endihunter |
Maintainer Contact: | endi1982@gmail.com (endi) |
Package Create Date: | 2016-10-31 |
Package Last Update: | 2017-10-24 |
Language: | PHP |
License: | Unknown |
Last Refreshed: | 2024-11-11 15:14:28 |
Package Statistics | |
---|---|
Total Downloads: | 184 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Navigation is a Laravel based (AdminArchitect oriented) package to handle dynamic menus. LinksProvider, RoutesProvider, EloquentProvider are provided out of the box.
Note, that adminarchitect/navigation
is based on AdminArchitect package and won't work without it.
composer require adminarchitect/navigation
Add following lines to your config/app.php
Terranet\Navigation\ServiceProvider::class
line to providers
array'Navigation' => Terranet\Navigation\Facade::class,
line to aliases
arrayRun:
php artisan vendor:publish --provider="Terranet\\Navigation\\ServiceProvider"
php artisan navigation:table
php artisan migrate
Navigation is based on Providers, each of them can provide a collection of navigable items and should realize one of default contracts or maybe define new one.
LinksProvider
: Provides a way to add static links: url => title;RoutesProvider
: Provides a way to add routes to menu;EloquentProvider
: Provides a way to add Eloquent models to a navigable collection.All usable providers are registered via config/navigation.php file -> providers
array.
To create a new provider, run: php artisan navigation <Name>
, then register it in config/navigation.php.
Any provider which extends EloquentProvider should provide a collection of items which implement NavigationItem contract. NavigationItem requires implementation of 3 simple methods:
id
;title
, name
, whatever identifies a model title.url(<url>)
or route(<name>, <params>)
for instance, to allow adding Posts
to a navigation you have to create a PostsProvider
, then modify your Post
model to look like in the following example:
php artisan navigation:provider PostsProvider
Provider
command will generate app\Http\Terranet\Administrator\Navigation\Providers\PostsProvider
class:
<?php
namespace App\Http\Terranet\Administrator\Navigation\Providers;
use Terranet\Navigation\Providers\EloquentProvider;
class PostsProvider extends EloquentProvider
{
/**
* Eloquent model.
*/
protected $model;
}
Now you only have to provide a valid eloquent $model, for instance App\Post
:
protected $model = \App\Post::class;
Next, register it in config/navigation.php
'providers' => [
...
\App\Http\Terranet\Administrator\Navigation\Providers\PostsProvider::class,
...
]
Navigable Eloquent model should implement NavigationItem contract, so App\Post
should be like:
class Post extends Model implements NavigationItem
{
protected $fillable = [
'user_id', 'title', 'slug', 'published', 'image',
];
public function navigationKey()
{
return $this->id;
}
public function navigationTitle()
{
return $this->title;
}
public function navigationUrl()
{
return route('posts.show', ['slug' => $this->slug]);
}
}