承接 topview-digital/laravel-lang-switcher 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

topview-digital/laravel-lang-switcher

Composer 安装命令:

composer require topview-digital/laravel-lang-switcher

包简介

Laravel Language Switcher

README 文档

README

GitHub release Scrutinizer Code Quality Build Status Code Intelligence Status License Total Downloads HitCount

Laravel Language Switcher

Middleware for Language Switcher and Helper for Locale Switch.

Implementations of middleware for language switch and helper for locale switch feature.

Requirements

  • PHP >= 7.0
  • MySQL >= 5.7
  • Laravel >= 5.5

Installation

Require the package via Composer:

composer require topview-digital/laravel-language-switch

Laravel will automatically register the ServiceProvider.

Publish Package

After installation, please publish the assets by below commands

php artisan lang-switch:publish

Configure Package

Please config your settings in config/lang-switch.php file, it should looks like below

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Laravel-Language-Switcher Database Settings
    |--------------------------------------------------------------------------
    |
    | Here are database settings for Laravel-Language-Switcher builtin tables connction.
    |
    */

    'database' => [
        // Database connection for guards tables.
        'connection' => '',

    ],

    //the field name of the storage in  cookie
    'field' => 'locale',
];

Once you confired your settings, you may run install command to setup the tables for the package.

php artisan lang-switch:install

Configure Global Middleware

Global usage To allow middleware automatically set your locale for all your routes, add the LangSwwitcher middleware in the $middleware property of app/Http/Kernel.php class:

    protected $middlewareGroups = [
        'web' => [
            // ...
            \TopviewDigital\LangSwitcher\Middleware\LangSwitcher::class,
        ],
        //...

Register Your Guard Middleware

In the bootstrap or your service provider

//Auth::user() is the guard method to get login user model, which could access the user field for setting locale
\TopviewDigital\LangSwitcher\Model\LangSwitcher::registerGuard(['class'=>'Auth','method'=>'user','middleware'=>'web']);

or you may reference the below sample language switcher controller to register your guard

<?php

namespace App\Backend\Controllers\API;

use App\User;
use Encore\Admin\Facades\Admin;
use App\Http\Controllers\Controller;
use TopviewDigital\LangSwitcher\Model\LangSwitcher;

class LanguageSelector extends Controller
{

    public function index()
    {
        LangSwitcher::registerGuard(['class' => 'Admin', 'method' => 'user', 'middleware' => 'admin']);
        LangSwitcher::switchLocale();
        return back();
    }
}

Hope you enjoy it! Thanks!

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固