安装地址: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'));
}
网友评论