这是错误=>
"message":“类型错误:传递给App\Listeners\SlackUserDropListener::handle()的参数1必须是App\Listeners\ App\Events\UserDropEvent,App\Events\UserDropEvent的实例”
我的代码如下:
namespace App\Listeners;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use GuzzleHttp\Client;
use App\Models\User;
use App\Models\UsersPermission;
use App\Models\UsersDrop;
use App\Models\Trace;
class SlackUserDropListener {
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param \App\Events\UserDropEvent $event
* @return void
*/
public function handle(App\Events\UserDropEvent $event) {
$user = $event->user;
$text = ">*Qualified lead has been dropped by agent*\n";
$text .= ">Client Name: ".$user->first_name." ".$user->last_name."\n";
$text .= ">Assigned Agent: ".$event->agent_name."\n";
$text .= ">Drop Reason: ".$event->drop_reason."\n";
$text .= ">Client BO Profile: https://***.com/users/edit/".$user->id."\n";
try{
$client = new Client;
$slack_channel = config('slack.webhookConsultants');
if(\App::environment() != "production") $slack_channel =
config('slack.webhookTest');
$client->request('POST', $slack_channel, ['json' => [
"text" => $text,
]]);
}catch(\Exception $e) {}
return "SlackUserDrop OK";
}
}
发布于 2019-01-22 09:57:02
所以,因为这一行:
namespace App\Listeners;
该文件中的所有调用都假定在该命名空间内。
因此,这一点:
App\Events\UserDropEvent $event
被解释为:
App\Listeners\App\Events\UserDropEvent $event
您可以用\
作为前缀,告诉PHP从名称空间根开始:
\App\Events\UserDropEvent $event
或者,您可以将其放在文件的顶部(与其他use
声明一起):
use App\Events\UserDropEvent;
在你的功能中这样做:
UserDropEvent $event
https://stackoverflow.com/questions/54312640
复制