/ * Я пытаюсь получить уведомления после того, как я предоставляю участникам собрание, способ получить enter code here
, он поставляется с неопределенным индексом id
Я пытался использовать json_encode, а затем использовать json_decode во время получения, но ничего не работает (у меня нет особых навыков в использовании json) * /
/ * контроллер
* /
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Notification;
use App\Meeting;
use App\Meeting_agenda;
use App\Meeting_minute;
use App\Notifications\MeetingNotify;
use App\User;
class MeetingsController extends Controller
{
public function store(Request $request, Meeting $meet)
{
$meeting=new Meeting();
$meeting->meeting_title=$request->meeting_title;
$meeting->meeting_venue=$request->meeting_venue;
$meeting->meeting_date=$request->meeting_date;
$meeting->meeting_type_id=$request->meeting_type_id;
$meeting->save();
foreach($request->input('name') as $agenda) {
$agendas= new Meeting_agenda();
$agendas->meeting_id=$meeting->id;
$agendas->name=$agenda;
$agendas->save();
}
$meet=Meeting::where('id',$meeting->id)->get();
$users=User::all();
json_encode(Notification::send($users, new
MeetingNotify($meet))) ;
return redirect('/meetings');
}
}
/ * Мой класс уведомлений * /
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class MeetingNotify extends Notification
{
use Queueable;
protected $meet;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($meet)
{
$this->meet=$meet;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
// return ['mail'];
return ['database'];
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toDatabase($notifiable)
{
return [
'meet'=>$this->meet,
// 'user'=>auth()->user()
];
}
public function toArray($notifiable)
{
return [
// 'meet'=>$this->meet,
];
}
}
/ * Мой клинок с возвращающимся взглядом * /
<a href="#">
@if((count(auth()->user()->unreadNotifications)>0))
@foreach(auth()->user()
->unreadNotifications as $notification)
<div class="dropdown-item"
onclick="markAsReadNotification()">
@include('includes.notifications.'.snake_case(class_basename($notification->type)))
</div>
@endforeach
@else
<p> No notifications!</p>
@endif
</a>
/ * includes.notifications.meeting_notify.blade.php * /
<a href="/Posts/{{$notification->data['meet']['id']}}">
{{json_decode($notification->data['meet']['id'])}}
</a>
/ * Данные, поступающие в базу данных * /
{"meet":[{"id":43,"meeting_title":"ordinary","meeting_type_id":2,"meeting_venue":"sdsd","meeting_date":"2019-5-30","minute":null,"created_at":"2019-05-29 15:53:58","updated_at":"2019-05-29 15:53:58"}]}
/ * Я ожидал, что собрание будет показано в моем блейде включения, чтобы перенаправить туда каждого пользователя
Ниже приведена ошибка * /
ErrorException (E_ERROR)
Undefined index: id (View: C
:\xampp\htdocs\BoardMeetingSytem\resources\views\includes\notifications\meeting_notify.blade.php) (View: C:\xampp\htdocs\BoardMeetingSytem\resources\views\includes\notifications\meeting_notify.blade.php) (View: C:\xampp\htdocs\BoardMeetingSytem\resources\views\includes\notifications\meeting_notify.blade.php)
Previous exceptions
Undefined index: id (View: C:\xampp\htdocs\BoardMeetingSytem\resources\views\includes\notifications\meeting_notify.blade.php) (View: C:\xampp\htdocs\BoardMeetingSytem\resources\views\includes\notifications\meeting_notify.blade.php) (0)
Undefined index: id (View: C:\xampp\htdocs\BoardMeetingSytem\resources\views\includes\notifications\meeting_notify.blade.php) (0)
Undefined index: id (0)