@Roni I have to agree with you. It is better if I write the displylogic in the models. Thanks for the note :)
But with this code i get the follow error:
Call to a member function displayAuthorName() on array
I would like to give you a better insight, maybe you can then help me to find a solution.
database
Schema::create('notifications', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('type');
$table->morphs('notifiable');
$table->text('data');
$table->timestamp('read_at')->nullable();
$table->timestamps();
});
save the notify:
//store notify for user in database
$postn = Post::find($request->post_id);
if($postn->user_id != Auth::id()) {
User::find($postn->user->id)->notify(new NotifyComment($comment));
}
Example entry in the database:
id: 03b0ede2-395f-408f-88f8-ab5e6c8e5023
type: App\Notifications\NotifyComment
notifiable_id: 2
notofiable_type: App\User
data: {"comment":{"body":"testcomment","user_id":1,"post_id":9,"privacy":3,"updated_at":"2018-10-16 19:02:31","created_at":"2018-10-16 19:02:31","id":74,"formatted_time":"1 second ago"},"user":{"id":1,"name":"name","team_id":1,"invited_from_id":null,"username":"testuser","email":"[email protected]","phone":null,"avatar":"/1/avatar/1537189269.jpg","slug":"testuser","birthday":"1980-01-30 00:00:00","gender":1,"created_at":"2018-09-16 19:20:16","updated_at":"2018-09-17 13:01:09","active":1,"activation_token":null},"post":{"id":9,"body":"testpost","titel":null,"articleText":null,"image":null,"image_thumbnail":null,"type":1,"status":1,"privacy":1,"user_id":2,"created_at":"2018-10-15 15:43:50","updated_at":"2018-10-15 15:43:50"},"profile":{"id":1,"user_id":1,"about":null,"webpage":null,"cover":"public/1/cover/jClNRrMhbfdQge205j0SucQSG6ZPGMkvHmPFvwVC.png","thumbnail":"/1/cover/thumb/1537353515thumbnail.png","privacy":3,"created_at":"2018-09-16 19:20:16","updated_at":"2018-09-19 10:38:35"}}
My next problem with the notifications is: How can I delete the notifications from the comment if the comment is deleted?