我需要在发送(或正在发送)电子邮件时执行一些代码。我的应用程序正在运行 Laravel 5.3。我按照此处所述的说明注册了 LogSentMessage 事件侦听器。
到目前为止,这是我的代码:
app/Listeners/LogSentMessage.php:
<?php
namespace App\Listeners;
use Illuminate\Mail\Events\MessageSending;
class LogSentMessage
{
public function __construct()
{
//
}
public function handle(MessageSending $event)
{
logger('Hello World');
}
}
Run Code Online (Sandbox Code Playgroud)
app/Listeners/EventServiceProvider.php:
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
protected $listen = [
'Illuminate\Mail\Events\MessageSending' => [
'App\Listeners\LogSentMessage',
],
];
public function boot()
{
parent::boot();
//
}
}
Run Code Online (Sandbox Code Playgroud)
它在两个不同的开发环境中完美工作,侦听器记录“Hello World”,但在我的生产环境中不起作用。可能是什么原因造成的?我正在使用数据库队列驱动程序将电子邮件发送存储为作业,但据此,这不应该成为问题:
Laravel 在发送邮件消息之前触发一个事件。请记住,此事件在发送邮件时触发,而不是在邮件排队时触发。您可以在 EventServiceProvider 中为此事件注册一个事件监听器:
另外,我的生产环境是通过Laravel Forge创建的 Homestead 镜像
我正在尝试使用 Elixir BrowserSync,这是 Laravel 的最新功能之一。
我将它添加到 gulp 文件中
elixir(function(mix) {
mix.sass('app.scss')
.browserSync();
});
Run Code Online (Sandbox Code Playgroud)
当我运行“gulp watch”时,它会输出此消息
[20:49:20] Using gulpfile ~/Desktop/laravel/gulpfile.js
[20:49:20] Starting 'watch'...
[20:49:20] Finished 'watch' after 11 ms
[BS] Proxying: http://homestead.app
[BS] Access URLs:
----------------------------------
Local: http://localhost:3000
External: http://10.9.0.48:3000
Run Code Online (Sandbox Code Playgroud)
使用 url http://localhost:3000自动启动浏览器但没有加载任何内容。
我认为问题与此行有关:[BS] 代理:http : //homestead.app
我正在使用LaravelCollective,因为Form Model Binding提供的好处.
我的问题是我需要从数据库填充一个带有类别的选择,所以我做了这样的事情:
{!! Form::select('size', Category::pluck('name'), null, ['placeholder' => 'Pick a category...']) !!}
Run Code Online (Sandbox Code Playgroud)
这个问题是生成的第一个选项有值="0".
我正在寻找一种雄辩的方式来生成一个数组['key'=>'value'],其中key是Id,value是名称.我知道我可以制作一个方法,获取所有类别并自己生成数组,但这不是我正在寻找的.
我有一个名为 RecordsUserActivity 的特征,它基本上在用户创建、更新或删除使用此特征的内容时在活动表中创建一条记录。这是代码:
trait RecordsUserActivity
{
protected static function boot()
{
parent::boot();
foreach (static::getModelEvents() as $event) {
static::$event(function ($model) use ($event) {
$model->addActivity($event);
});
}
}
protected function addActivity($event)
{
$newActivity = [
'subject_id' => $this->id,
'subject_type' => get_class($this),
'action' => $event,
'user_id' => (Auth::id()) ?? null,
];
if ($event == 'updated') {
$newActivity['data'] = json_encode($this->getDirty());
}
UserActivity::create($newActivity);
}
protected static function getModelEvents()
{
if (isset(static::$recordEvents)) {
return static::$recordEvents;
}
return ['created', 'deleted', 'updated'];
}
}
Run Code Online (Sandbox Code Playgroud)
然后我有另一个特征,它记录使用它的模型中的属性更改。这是代码:
trait RecordsPropertyChangelog
{ …Run Code Online (Sandbox Code Playgroud) 我正在按照教程创建一个新类型.这是我的代码:
data Shape = Circle Float Float Float | Rectangle Float Float Float Float
Run Code Online (Sandbox Code Playgroud)
当我用ghci加载文件时,我键入:
Circle 10 20 5
Run Code Online (Sandbox Code Playgroud)
它打印这个:
<interactive>:29:1:
No instance for (Show Shape) arising from a use of ‘print’
In a stmt of an interactive GHCi command: print it
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?
我有一个运行Laravel 5.3的应用程序.
我需要对表中的所有记录进行修改,这是我的代码:
Car::all()->each(function($car){
$car->created_by = 10;
$car->updated_by = 15;
$car->save();
});
Run Code Online (Sandbox Code Playgroud)
问题是created_by字段正在正确保存但updated_by没有.即使我dump($car)以前使用save()行,我也可以看到两个字段都已被修改.我还添加了两个字段$fillable(我知道,这是用于大规模分配,但以防万一..).