承接 royvoetman/laravel-flash-alerts 相关项目开发

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

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

royvoetman/laravel-flash-alerts

Composer 安装命令:

composer require royvoetman/laravel-flash-alerts

包简介

Automatically flash success alerts in resources controllers: `store`, `update` and `destroy` methods.

README 文档

README

This packages will automatically flash success messages to the session when a controller's: store, update or destroy method was successfully executed.

An execution is considered successful when no exceptions were raised and no messages are defined in the current session under the key warning.

Latest Version MIT Licensed Total Downloads

Installation

composer require royvoetman/laravel-flash-alerts

Add FlashAlerts middleware to the routeMiddleware array in app/Http/Kernel.php

 /**
  * The application's route middleware.
  *
  * These middleware may be assigned to groups or used individually.
  *
  * @var array
  */
 protected $routeMiddleware = [
    ...
    'flash.alerts' => \RoyVoetman\LaravelFlashAlerts\Middleware\FlashAlerts::class
 ];

Add the FlashesAlerts trait to your applications BaseController

<?php

namespace App\Http\Controllers;

use RoyVoetman\LaravelFlashAlerts\Traits\FlashesAlerts;
...

abstract class Controller extends BaseController
{
    use FlashesAlerts;

    ...
}

Signature

public function registerAlertMiddleware(string $model, array $except = []);
  • $model
    • A string used in the flash messages for example $model = 'Book' will result in: The Book has been successfully added
  • $except
    • An array of methods that are skipped while registering middleware.

Usage

If the middleware is registered and a store, update or destory method has been successfully executed. A message will be flashed in the current session under the key alert.

If the current session has a message under the key warning or an exception is thrown, the request will not be considered successful.

Example

<?php

namespace App\Http\Controllers;

class BookController extends Controller
{    
    /**
     * BookController constructor.
     */
    public function __construct()
    {
        parent::__construct();
        
        $this->registerAlertMiddleware('Book');
    }
    
    ...
}

Ignoring methods

<?php

namespace App\Http\Controllers;

class BookController extends Controller
{    
    /**
     * BookController constructor.
     */
    public function __construct()
    {
        parent::__construct();
        
        $this->registerAlertMiddleware('Book', ['destroy']);
    }
    
    public function store()
    {
        // Will flash alert

        return redirect()->route('books.index');
    }

    public function destroy()
    {
        // Won't flash alert

        return redirect()->route('books.index');
    }
    ...
}

Displaying flash alerts

@if (session()->has('alert'))
    <div class="alert alert-success" role="alert">
        {{ session('alert') }}
    </div>
@endif

Change Alert messages

php artisan vendor:publish --provider="RoyVoetman\LaravelFlashAlerts\FlashAlertsServiceProvider" 

This will place the overwritable translations under resources/lang/vendor/laravel-flash-alerts

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Contributions are welcome and will be fully credited. We accept contributions via Pull Requests on Github.

Pull Requests

  • PSR-2 Coding Standard - The easiest way to apply the conventions is to install PHP Code Sniffer.
  • Document any change in behaviour - Make sure the README.md and any other relevant documentation are kept up-to-date.
  • Create feature branches - Don't ask us to pull from your master branch.
  • One pull request per feature - If you want to do more than one thing, send multiple pull requests.

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-08-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固