tjventurini / tags
用于我基于laravel的首页的标签包。
这个包的规范仓库似乎已不存在,因此包已被冻结。
v0.0.9
2018-11-08 19:45 UTC
Requires
- backpack/crud: ^3.4.0
- cviebrock/eloquent-sluggable: ^4.3
- laravel/framework: 5.5.*
Requires (Dev)
- tjventurini/mini-bootstrap-theme: ^0.0.3
README
这个包为我的基于laravel的博客提供标签功能。它需要Backpack for Laravel,因此您需要安装它。
安装
此包可通过 packagist 获取。使用以下命令进行安装。
composer require tjventurini/tags
迁移
您需要运行标签表的迁移。
php artisan migrate
配置
您需要发布包配置。
php artisan vendor:publish --provider="Tjventurini\Tags\TagsServiceProvider" --tag=config
视图(可选)
即使您没有发布,视图也通过 tags::view-name
可用。
php artisan vendor:publish --provider="Tjventurini\Tags\TagsServiceProvider" --tag=views
翻译(可选)
即使您没有发布,翻译也通过 tags::tags.key
可用。
php artisan vendor:publish --provider="Tjventurini\Tags\TagsServiceProvider" --tag=lang
播种(可选)
该包为标签表提供播种。
artisan db:seed --class="Tjventurini\Tags\Database\Seeds\TagsSeeder"
Backpack
现在您应该准备好更新背包管理面板。打开 resources/views/vendor/backpack/base/inc/sidebar_content.blade.php
并添加以下行。
<li><a href="{{ backpack_url('tag') }}"><i class="fa fa-tag"></i> <span>{{ trans('tags::tags.menu_item') }}</span></a></li>
最后,需要发布用于背包 CRUD 的按钮。
php artisan vendor:publish --provider="Tjventurini\Tags\TagsServiceProvider" --tag=backpack
配置
路由
/*
|--------------------------------------------------------------------------
| Tjventurini\Tags Routes
|--------------------------------------------------------------------------
|
| In this file you will find all routes needed for this package to work in
| in the backpack backend as well as the frontend.
|
*/
Route::group([
'prefix' => config('backpack.base.route_prefix', 'admin'),
'middleware' => ['web', config('backpack.base.middleware_key', 'admin')],
'namespace' => 'Tjventurini\Tags\App\Http\Controllers\Admin',
], function () {
CRUD::resource('tag', 'TagCrudController');
});
Route::group([
'prefix' => 'tags',
'middleware' => ['web'],
'namespace' => 'Tjventurini\Tags\App\Http\Controllers',
], function () {
// show tags
Route::get('/', 'TagController@index')->name('tags');
// show single tags
Route::get('/{slug}', 'TagController@tag')->name('tags.tag');
});
路由前缀
/*
|--------------------------------------------------------------------------
| Route Prefix
|--------------------------------------------------------------------------
|
| In this section you can define the route prefix of this package.
|
*/
'route_prefix' => 'tags',
视图
/*
|--------------------------------------------------------------------------
| Views
|--------------------------------------------------------------------------
|
| In this section you can define the views to show when the routes are
| called.
|
*/
// view to show all articles
'view_tags' => 'tags::all',
// view to show single article
'view_tag' => 'tags::tag',
关系
/*
|--------------------------------------------------------------------------
| Relationships
|--------------------------------------------------------------------------
|
| In this section you can define other implementations of tags that extend
| the tags model of this package. This way we can list the relationships
| of tags in tag view.
|
*/
'relationships' => [
// 'articles' => Tjventurini\Articles\App\Models\Tag::class,
],
验证
/*
|--------------------------------------------------------------------------
| Validation
|--------------------------------------------------------------------------
|
| In this section you can change the validation rules of the tags request.
|
*/
'rules' => [
'name' => 'required|min:2|max:50',
'slug' => 'unique:tags,slug',
'image' => 'required|string',
'description' => 'required|min:50|max:255',
],
扩展标签模型
如果您需要向标签模型添加更多功能,则可以简单地为您的包扩展模型。以下是tjventurini/articles包的示例实现。
<?php
namespace Tjventurini\Articles\App\Models;
use Backpack\CRUD\CrudTrait;
use Illuminate\Database\Eloquent\Model;
use Cviebrock\EloquentSluggable\Sluggable;
use Cviebrock\EloquentSluggable\SluggableScopeHelpers;
class Tag extends \Tjventurini\Tags\App\Models\Tag
{
/*
|--------------------------------------------------------------------------
| RELATIONS
|--------------------------------------------------------------------------
*/
public function articles()
{
return $this->belongsToMany('Tjventurini\Articles\App\Models\Article');
}
}