Answer the question
In order to leave comments, you need to log in
How to implement lazy loading of an unknown laravel model?
This is the notification model:
This is how I create a new notification
/**
Создает в таблице modernote уведомление пользователю
param $user_id - id пользователя, которому показываем уведомление
param $model_type - класс модели, с которой связано уведомление (не обязательное)
param $model_id - id модели, связанной с уведомлением (не обязательное)
param $header - заголовок
param $message - message тело
param $lang_var - переменная, которая подставляется в ту или иную языковую переменную уведомления
return boolean
*/
public function create( $user_id, $model_type=null, $model_id=null, $header, $message, $lang_var )
{
$newModerNote = new ModerNote;
$newModerNote->user_id = $user_id;
$newModerNote->model_type = $model_type;
$newModerNote->model_id = $model_id;
$newModerNote->header = $header;
$newModerNote->message = $message;
$newModerNote->lang_var = $lang_var;
$newModerNote->save();
return true;
}
$user_notifications = ModerNote::where('user_id', $user_id)
->orderBy('id','DESC')
->paginate(10);
Answer the question
In order to leave comments, you need to log in
First, you are most likely confusing lazy loading with greedy loading. You obviously need exactly the greedy one.
And secondly: I recommend that you read this section of the documentation , which describes polymorphic relationships. It is very likely that they will help you solve this problem.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question