7

在 Laravel 5.7 中更改成功、错误和原色的最佳方法是什么?

我有 email.blade.php 通过php artisan vendor:publish --tag=laravel-notifications

...
{{-- Action Button --}}
@isset($actionText)
<?php
    switch ($level) {
        case 'success':
        case 'error':
            $color = $level;
            break;
        default:
            $color = 'primary';
    }
?>
@component('mail::button', ['url' => $actionUrl, 'color' => $color])
...

模板使用'success','error''primary'为按钮着色,但我可以在哪里更改它们的值?

4

3 回答 3

16

这是最好和正确的方法

https://laracasts.com/series/whats-new-in-laravel-5-4/episodes/7

(我会提取) - 运行

php artisan vendor:publish --tag=laravel-mail, this will create vendors/html folder in your views directory.

然后创建一个新的主题文件

/resources/views/vendor/mail/html/themes/my_theme.css

然后在

config/mail.php

设置新主题

        'theme' => 'my_theme',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],

现在您可以设置自己的 CSS 并创建任何新的按钮颜色。

@component('mail::button', ['url' => $url, 'color' => 'success'])
View Group
@endcomponent
于 2019-01-23T18:36:38.693 回答
3

只需运行php artisan vendor:publish --tag=laravel-mail,这将在您的视图目录中创建 vendor/html 文件夹。

然后编辑/resources/views/vendor/mail/html/themes/default.css文件并更改.button-primary类。

此外,如果 CSS 更改还不够,您还可以访问每个邮件通知组件的所有 HTML 代码。

于 2018-10-08T09:20:18.883 回答
0

也许,最好的方法是创建 ColorHelper 类?

class ColorHelper {

    public static function level($level) {
        if(method_exists ( $this , $level )) {
            call_user_func($level);
        } else {
            return false;
        }
    }

    public static function success() {
        return '#00FF00';
    }

    public static function error() {
        return '#FF0000';
    }

}
于 2018-09-24T11:31:09.750 回答