安裝地址:https://github.com/fenos/Notifynder
具體安裝:
"fenos/notifynder": "^4.0"
composer update 或者 composer require fenos/notifynder
Providers array:
Fenos\Notifynder\NotifynderServiceProvider::class,
Aliases array:
'Notifynder' => Fenos\Notifynder\Facades\Notifynder::class,
php artisan vendor:publish --provider="Fenos\Notifynder\NotifynderServiceProvider"
php artisan migrate
OK 到此安裝完畢
接下來我們使用它
1.你需要創建模板
這里我們運用文檔上的例子,創建一個類叫sayhello,然后模板hello good。。。。
php artisan notifynder:create:category "sayhello" "hello good {extra.period_day}"
2.接下來你就可以發送信息
use Notifynder;
$user_sender_id = 1; // User sender
$user_receiver_id = 2; // User that receive the notification
$period_day = (is_morning()) ? 'morning' : 'evening';
$notifynder->category('sayhello')
->from(1)
->to(2)
->url('http://localhost')
->extra(compact('period_day'))
->send();
到此信息發送完畢
OK 接下來我們在客戶端查看
use Fenos\Notifynder\Models\Notification;
use Notifynder;
....
public function myNews(Request $request){
//dd($this->user);
$message = $this->user->getNotifications(15,1,'desc');
return view('home.my_news',compact('message'));
}
public function newsDetail(Request $request){
$id = $request->get('id',0);
$query = Notification::where('id',$id);
if($id){
$query->update(['read'=>2]);
return response()->json(['success'=>1]);
}
$news_detail = $query->findOrFail($id);
return view('home.news_detail',compact('news_detail'));
}