laravel 5 简易博客

0.0.2 2015-04-16 07:01 UTC

This package is not auto-updated.

Last update: 2024-09-28 16:25:54 UTC


README

注意:请不要立即使用此包。仍在开发中。

这是一个为laravel 5设计的简易博客包,目标是提供一个可扩展博客文章的起点。

安装

首先我们需要通过composer安装它

composer require "webinfinita/blog"

然后我们需要添加服务提供者

// config/app.php

<?php

return [
	...
	...
	'providers' => [
		...
		...
        'Webinfinita\Blog\Providers\BlogServiceProvider',
    ],
];

发布迁移和视图

php artisan vendor:publish

我们使用一个特质来让用户拥有多个帖子

// app/User.php

<?php namespace App;

...
use Webinfinita\Blog\Traits\HasManyPosts;

class User extends Model implements ... {

	use Authenticatable, CanResetPassword, HasManyPosts;
	...

为了限制对不属于用户的帖子的访问,我们需要注册一个中间件

// app/Http/Kernel.php

<?php namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel {
	
	...
	
	protected $routeMiddleware = [
		...
        'post.owner' => 'Webinfinita\Blog\VerifyPostOwner',
	];

}