machaen/blog

博客插件

维护者

详细信息

github.com/machaen/BlogJM

源代码

问题

安装: 6

依赖: 0

建议: 0

安全: 0

星星: 0

关注者: 1

分支: 0

公开问题: 0

语言:CSS

dev-master 2017-03-02 00:01 UTC

This package is not auto-updated.

Last update: 2024-09-18 20:07:40 UTC


README

一个简单的插件,用于生成环境博客

安装和配置

1 - 在文件 composer.json 中添加以下行,并执行 composer update

{
    "require": {
        "machaen/blog": "dev-master"
    }
}

2 - 在文件 config/app.php 中添加必要的提供者和别名

'providers' => [
		'Illuminate\Html\HtmlServiceProvider',
		'Dimsav\Translatable\TranslatableServiceProvider',
		'Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider',
		'Machaen\Blog\BlogServiceProvider',
	]
	.....
'aliases' => [
    	'Form'                  => 'Illuminate\Html\FormFacade',
    	'LaravelLocalization'   => 'Mcamara\LaravelLocalization\Facades\LaravelLocalization',
	]

3 - 使用以下命令添加公共文件

php artisan vendor:publish

4 - 将文件 blog.cssblog.js 导入到我们的项目中

<head>
    <link href="{{ asset('css/blog.css') }}" rel="stylesheet">  
    <script src="{{ asset('js/blog.js') }}"></script>  
</head>

5 - 在 app/Http/kernel.php 中添加中间件

...
protected $routeMiddleware = [
	'localize'              => '\Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes',
	'localizationRedirect'  => '\Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter',
	'localeSessionRedirect' => '\Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect'
];

6 - 在 app/Http/routes.php 中添加路由

/*** 
Other routes
.............
 ***/
 
Route::group(
[
	'prefix' 		=> LaravelLocalization::setLocale(),
	'middleware' 	=> [ 'localeSessionRedirect', 'localizationRedirect' ]
],
function(){
    Route::get(LaravelLocalization::transRoute('blog.blog-index'),['as' => 'blog.index', 'uses' => '\Machaen\Blog\BlogController@index']);
    Route::get(LaravelLocalization::transRoute('blog.blog-show'),['as' => 'blog.show', 'uses' => '\Machaen\Blog\BlogController@show']);
});

7 - 最后,您需要迁移并插入种子数据

	php artisan migrate:refresh --seed

翻译按钮

需要配置一个按钮,允许更改我们的区域设置并设置语言(仅在预览帖子中)。因此,我们必须在动作链接中插入以下条件,例如

	/*----------  PREVIEW BLOG POST  ----------*/
	
	/* This line call the function "getRouteBlog" that's create a link with the parameters necessary for translate the current route. Here we past the route at layout our project */
	@extends('app', ['route_blog' => \Machaen\Blog\Helpers::getRouteBlog($post->id)])

	/*----------  LAYOUT  ----------*/
	
	@if(LaravelLocalization::getCurrentLocale() == 'en')
      <a href="{{ isset($route_blog) ? $route_blog : LaravelLocalization::getLocalizedURL('es') }}">ESPAÑOL</a>
    @else
      <a href="{{isset($route_blog) ? $route_blog : LaravelLocalization::getLocalizedURL('en') }}">ENGLISH</a>
    @endif