Я следую: https://laracasts.com/series/lets-build-a-forum-with-laravel/episodes/43
Итак, в конце этого эпизода я понял, что, когда я создал пользователя B для ответа на тему, созданную пользователем A, я получаю следующую ошибку
Ошибка: запрос не выполнен с кодом состояния 500
Хотя ответ сохраняется в базе данных, и я вижу его, когда обновляю страницу, он просто не рендерится с vue и выдает ошибку.
Пристальный взгляд на вкладку сети
message Too few arguments to function App\ThreadSubscription::notify(), 0 passed in C:\wamp64\www\forum\vendor\laravel\framework\src\Illuminate\Support\HigherOrderCollectionProxy.php on line 60 and exactly 1 expected
exception Symfony\Component\Debug\Exception\FatalThrowableError
file C:\wamp64\www\forum\app\ThreadSubscription.php
Это модель ThreadSubscription
class ThreadSubscription extends Model
{
protected $guarded = [];
public function user()
{
$this->belongsTo(User::class);
}
public function thread()
{
return $this->belongsTo(Thread::class);
}
public function notify($reply)
{
$this->user->notify(new ThreadWasUpdated($this->thread, $reply));
}
}
Это UserNotificationsController
class UserNotificationsController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
return auth()->user()->unreadNotifications;
}
public function destroy(User $user, $notifiationId)
{
auth()->user()->notifications()->findOrFail($notifiationId)->markAsRead();
}
}
Это UserNotificationsFactory
$factory->define(DatabaseNotification::class, function (Faker $faker) {
return [
'id' => Uuid::uuid4()->toString(),
'type' => 'App\Notifications\ThreadWasUpdated',
'notifiable_id' => function () {
return auth()->id() ?: factory('App\User')->create()->id;
},
'notifiable_type' => 'App\User',
'data' => ['foo' => 'bar']
];
});
И это метод addReply в модели User
public function addReply($reply) {
$reply = $this->replies()->create($reply);
$this->subscriptions->filter(function($sub) use ($reply) {
return $sub->user_id != $reply->user_id;
})->each->notify();
return $reply;
}
EDIT: я забыл передать $ reply каждому-> notify () в методе addReply.Но теперь я получаю другую ошибку.
message App\ThreadSubscription::user must return a relationship instance, but "null" was returned. Was the "return" keyword used?
exception LogicException
file C:\wamp64\www\forum\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasAttributes.php