lchhieu/push_view

PushView 包支持在 Laravel 中向视图添加 JavaScript

dev-master 2018-11-14 04:18 UTC

This package is auto-updated.

Last update: 2024-09-13 17:14:48 UTC


README

  • PushView 包支持在 Laravel 中向视图添加 JavaScript
  • 当您希望自动从 PHP 和客户端接收翻译后的文本时,此包将非常有用
class BaseController extends Controller
{
    public function index()
    {
        \PushViewJS::put([
            'translate' => ['confirmation' => trans('labels.confirmation')]
        ]);
        
        return view('welcome');
    }
}

<script>
window.Core = window.Core || {};
Core.translate = {"confirmation":{"title":"Are you sure?","confirm_dirty_form":"Do you want to save the changes made before switching?","yes":"Yes","skip_continue":"Skip & Continue","cancel":"Cancel","delete":{"yes":"Yes delete it!","text":"You won't be able to revert this!"}}};
</script>

安装

  1. 使用 Composer 安装
composer require lchhieu/push_view

如果您正在使用 Laravel 5.5 或更高版本,您可以从现在开始使用此包。PushView 会被 Laravel 框架自动发现。

  1. 将服务提供者添加到您的 config/app.php 文件中的 providers 数组中。
    'Lchhieu\PushView\Providers\ViewServiceProvider::class', 
  1. config/app.php 中添加外观
    'PushViewJS'      => Lchhieu\PushView\Facades\JavaScriptFacade::class
  1. 最后,通过运行以下命令发布包配置

    php artisan vendor:publish --provider="Lchhieu\PushView\Providers\ViewServiceProvider"