tjventurini / articles
博客文章。
该包的规范仓库似乎已丢失,因此该包已被冻结。
v0.1.10
2018-11-24 18:22 UTC
Requires
- backpack/crud: ^3.4.0
- cviebrock/eloquent-sluggable: ^4.3
- laravel/framework: 5.5.*
- parsedown/laravel: ^1.1
- tjventurini/tags: ^0.0.9
Requires (Dev)
- tjventurini/mini-bootstrap-theme: ^0.0.3
README
此包为基于 laravel 的博客提供文章功能。它需要 Backpack for Laravel,因此您需要安装它。
安装
此包通过 packagist 提供。使用以下命令安装。
composer require tjventurini/articles
迁移
您需要运行文章表的迁移。
php artisan migrate
配置
您需要发布包配置。
php artisan vendor:publish --provider="Tjventurini\Articles\ArticlesServiceProvider" --tag=config
视图(可选)
即使不发布,视图也可通过 articles::view-name
获取。
php artisan vendor:publish --provider="Tjventurini\Articles\ArticlesServiceProvider" --tag=views
翻译(可选)
即使不发布,翻译也可通过 articles::articles.key
获取。
php artisan vendor:publish --provider="Tjventurini\Articles\ArticlesServiceProvider" --tag=lang
播种(可选)
该包为文章表提供播种。
artisan db:seed --class="Tjventurini\Articles\Database\Seeds\ArticlesSeeder"
Backpack
现在,您应该准备好更新背包管理面板。打开 resources/views/vendor/backpack/base/inc/sidebar_content.blade.php
并添加以下行。
<li><a href="{{ backpack_url('article') }}"><i class="fa fa-file-text"></i> <span>{{ trans('articles::articles.menu_item') }}</span></a></li>
Articles 使用 tjventurini/tags 包进行标签分类。要在背包管理面板中使用它,您还需要将以下行添加到 sidebar_content.blade.php
。有关标签的更多信息,请访问 tjventurini/tags 仓库。
<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\Articles\ArticlesServiceProvider" --tag=backpack
配置
路由
/*
|--------------------------------------------------------------------------
| Tjventurini\Articles 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\Articles\App\Http\Controllers\Admin',
], function () {
CRUD::resource('article', 'ArticleCrudController');
});
Route::group([
'prefix' => config('articles.route_prefix', 'articles'),
'middleware' => ['web'],
'namespace' => 'Tjventurini\Articles\App\Http\Controllers',
], function () {
// show articles
Route::get('/', 'ArticleController@index')->name('articles');
// show article
Route::get('/{slug}', 'ArticleController@article')->name('articles.article');
});
路由前缀
/*
|--------------------------------------------------------------------------
| Route Prefix
|--------------------------------------------------------------------------
|
| In this section you can define the route prefix of this package.
|
*/
'route_prefix' => 'articles',
视图
/*
|--------------------------------------------------------------------------
| Views
|--------------------------------------------------------------------------
|
| In this section you can define the views to show when the routes are
| called.
|
*/
// view to show all articles
'view_articles' => 'articles::articles',
// view to show single article
'view_article' => 'articles::article',
验证
/*
|--------------------------------------------------------------------------
| Validaton
|--------------------------------------------------------------------------
|
| In this section you can change the validation rules for articles.
|
*/
'rules' => [
'name' => 'required|min:5|max:255',
'slug' => 'unique:articles,slug',
'image' => 'required|string',
'intro' => 'required|min:50|max:255',
'content' => 'required|min:255',
'tags' => 'required',
],
日期格式
/*
|--------------------------------------------------------------------------
| Date Format
|--------------------------------------------------------------------------
|
| In this section you can define the date format used for portfolios.
|
*/
'date_format' => 'd.m.Y',
编辑器 / 内容类型
/*
|--------------------------------------------------------------------------
| Editor / Content Type
|--------------------------------------------------------------------------
|
| In this section you can select the editor to use in articles crud and
| therefore some how define which type of content you want to use.
|
| E.g you could decide to use simplemde editor and therefore change your
| content type from html to markdown.
|
| Visit https://backpackforlaravel.com/docs/3.4/crud-fields for more
| information.
|
*/
'editor' => 'wysiwyg',