machaen / blog
Blog Plugin
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Language:CSS
Requires
- php: ^5.0
- dimsav/laravel-translatable: 5.4
- fzaninotto/faker: ^1.5
- illuminate/html: 5.*
- mcamara/laravel-localization: 1.0.*
This package is not auto-updated.
Last update: 2025-03-05 22:45:26 UTC
README
Simple plugin to generate an enviroment blog
Installation and configuration
1 - Add to file composer.json
the next line and eject a composer update:
{ "require": { "machaen/blog": "dev-master" } }
2 - Add the providers and aliases necessary to file 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 - Public files whith the next command:
php artisan vendor:publish
4 - Import files blog.css
and blog.js
inside our project:
<head> <link href="{{ asset('css/blog.css') }}" rel="stylesheet"> <script src="{{ asset('js/blog.js') }}"></script> </head>
5 - Add middlewares to app/Http/kernel.php
:
... protected $routeMiddleware = [ 'localize' => '\Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes', 'localizationRedirect' => '\Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter', 'localeSessionRedirect' => '\Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect' ];
6 - Add routes to 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 - Finally you have to migrate and insert your seeds:
php artisan migrate:refresh --seed
Translations button
It's necessary configure a button that's allow change our locale and set the lenguage (only in the preview post). So, we have to insert the next condition inside our action link, for example:
/*---------- 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