Во-первых, я хотел бы извиниться, если это дублированный или повторяющийся вопрос.Laravel Dependency Injection, используя функцию настройки
Я «новый» для инъекций зависимости. Я понял, как это сделать в функциях __constructor, но не уверен в функции setter. Я хочу правильно использовать DI, вопрос: я использую это правильный путь в следующем коде:
public function setNotification(Notification $notification)
{
$this->notification = $notification;
}
public function handle(PostWasCommented $event)
{
$post = $event->comment->post;
$post->load('blog');
$followers = $post->followers;
$online_ids = Redis::pipeline(function($pipe) use ($event, $followers, $post)
{
foreach($followers as $follower){
if(Auth::id() != $follower->user_id){
$this->setNotification(new Notification());
$this->notification->from_id = Auth::id();
$this->notification->to_id = $follower->user_id;
$this->notification->type = 'PostComment';
$this->notification->source_id = $event->comment->id;
$this->notification->parent_id = $event->comment->post_id;
$this->notification->blog_name = $post->blog->link_name;
if($post->user_id == $follower->user_id)
$this->notification->my_post = true;
else
$this->notification->my_post = false;
$this->notification->save();
$pipe->get('user'.$follower->user_id);
}
}
});
я узнал, используя массовое назначение может может помочь мне :)
Я не уверен, что я вижу инъекцию зависимости здесь. Единственное, что _may_ qualify является аргументом 'PostWasCommented', но я не думаю, что это то, о чем вы просите здесь. –