chrisjk123 / laravel-blogger
博客包
Requires
- php: ^7.1
- artesaos/seotools: ^0.17.1
- laravel/framework: ~5.8|^6.0
Requires (Dev)
- orchestra/testbench: 3.8.*
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-09-05 23:20:09 UTC
README
目录
介绍
此包是一个包含最大化的模型、迁移和种子器的博客数据库,有助于快速搭建。安装包后,您只需将HasPosts
特性添加到Eloquent模型中,以关联用户。
以下是代码示例
// Alias namespace path: // Chriscreates\Blog\Post // Chriscreates\Blog\Category // Chriscreates\Blog\Tag // Chriscreates\Blog\Comment // Search by the short whereCategories method OR use whereCategory() and specify the field $results = Post::whereCategories($categories = null)->get(); $results = Post::whereCategory($field, $operator, $value)->get(); // Search by Category ID OR IDs $results = Post::whereCategories(1)->get(); $results = Post::whereCategory('id', 1)->get(); ---------- $results = Post::whereCategories([3, 6, 7])->get(); $results = Post::whereCategory('id', [3, 6, 7])->get(); // Search by Category name OR names $results = Post::whereCategories('Izabella Bins II')->get(); $results = Post::whereCategory('name', 'Izabella Bins II')->get(); ---------- $results = Post::whereCategories(['Izabella Bins II', 'Osborne Fay'])->get(); $results = Post::whereCategory('name', ['Izabella Bins II', 'Osborne Fay'])->get(); // Search by Category model or a Category Collection $category = Category::where('id', 7)->first(); $results = Post::whereCategories($category)->get(); ---------- $categories = Category::whereIn('id', [3, 6, 7])->get(); $results = Post::whereCategories($categories)->get(); // Search by related Post (tags or category) $post = Post::find(8); $results = Post::relatedByPostTags($post)->get(); ---------- $results = Post::relatedByPostCategory($post)->get(); // Search by published Posts only Post::published()->get(); ---------- Post::publishedLastMonth()->get(); ---------- Post::publishedLastWeek()->get(); // Search by unpublished Posts only Post::notPublished()->get(); // Search by scheduled Posts only Post::scheduled()->get(); // Search by drafted Posts only Post::draft()->get(); // Order by latest published Post::orderByLatest()->get();
需求
此包需要Laravel 5.8或更高版本,PHP 7.2或更高版本,以及支持json字段和MySQL兼容函数的数据库。
安装
注意:Laravel Blogger要求您在安装前设置用户身份验证。对于基于Laravel 5.*的项目,请运行
make:auth
Artisan命令。对于基于Laravel 6.*的项目,请参阅官方指南以开始。
您可以通过composer安装此包
composer require chrisjk123/laravel-blogger
使用blog:install
Artisan命令发布主要配置文件
php artisan blog:install
这是已发布配置文件的内容,如果您的User
类位于不同的目录或具有不同的主键,则可以在此处更改。
/* |-------------------------------------------------------------------------- | User relations |-------------------------------------------------------------------------- | | This is the default path to the User model in Laravel and primary key. | You are free to change this path to anything you like. | */ 'user' => [ 'user_class' => \App\User::class, 'user_key_name' => 'id', ],
可选地,您可以遵循artesaos/seotools指南,以帮助为您的公共前端提供一些常见的SEO技术。
{{-- Within the head of your app.blade.php file --}} {!! SEOMeta::generate() !!} {!! OpenGraph::generate() !!}
测试
使用以下命令运行测试
composer test
用法
您只需将HasPosts
添加到您的User模型中即可开始。
namespace App; use Chriscreates\Blog\Traits\User\HasPosts; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; class User extends Authenticatable { use Notifiable, HasPosts; // ... } // Retrieve the posts created by the user(s) $user->posts; // Retrieve the comments created by the guest/user(s) $user->comments;
{{-- Print the published post markdown content --}}
{!! $post->parsed_markdown !!}
此外,在配置文件中,默认设置为允许用户和公开评论在帖子上的设置为true。
/* |-------------------------------------------------------------------------- | Post commenting options |-------------------------------------------------------------------------- | | The default for commenting on posts is enabled, as well as guest | commenting. Feel free to change these conditions to false. | */ 'posts' => [ 'allow_comments' => true, 'allow_guest_comments' => true, ],
您可以使用blog:setup
Artisan命令快速设置。这将发布路由、控制器和视图。可选地,您可以通过指定数据选项--data
使用factory()
数据填充数据库。
php artisan blog:setup --data
变更日志
有关最近更改的更多信息,请参阅CHANGELOG。
安全
如果您发现任何安全相关的问题,请通过christopherjk123@gmail.com发送电子邮件,而不是使用问题跟踪器。
致谢
许可
MIT许可(MIT)。有关更多信息,请参阅许可文件。