notify Last updated: 2022-10-04

For sure you will need to put notifications in one or more cases
That's why we provide this for you
Suppose you have set up your notification system in your database and you want to show these notifications

You can divide it according to your needs

 

Suppose we are now displaying the latest waiting members from the same members table in notifications or even in a custom table

 

Let's do it in the terminal

php artisan dash:make-notify PendingUsers
PendingUsers Notification generated

We have created PendingUsers  class 

this object created in default path app/Dash/Notifications

<?php
namespace App\Dash\Notifications;
use App\Models\User;
use Dash\Notification;

class PendingUsers extends Notification {

	public static function stack() {
		return [
			'js' => [
				url('test.js'), // js url
			],
			'blade' => [
				'test', //test.blade.php
			],
		];
	}

 
	public static function unreadCount() {
		return User::where('status','pending')->count();
	}

 
	public static function content() {
		$lists = User::where('status','pending')->all();
		$data  = '';
		foreach ($lists as $list) {
			$data .= view('PendingUsers_notifications', ['list' => $list])->render();
		}
		return $data;
	}
}

We include the object in DashServiceProvider 

 
	public static function notifications() {
		return [
			\App\Dash\Notifications\PendingUsers::class,
		];
	}

Let's explain the content of the object and each method

unreadCount() method 

It is responsible for the number of values that come out of the table and can be allocated according to the read and unread or according to more than one case as you see in the example

public static function unreadCount() {
		return User::where('status','pending')->count();
	}

 

stack() method

It is responsible for the possibility of implanting the JavaScript code, whether it is from an explicit JavaScript file or through a blade file 

One of them can be dispensed with, and the other is sufficient, and they can be completely dispensed with if there is no need 

	public static function stack() {
		return [
			'js' => [
				url('test.js'), // js url
			],
			'blade' => [
				'test', //test.blade.php
			],
		];
	}

 

 

content() method

also note that this method is for the display content in the notification drop-down list

 

 

public static function content() {
		$lists = User::all();
		$data  = '';
		foreach ($lists as $list) {
			$data .= view('PendingUsers_notifications', ['list' => $list])->render();
		}
		return $data;
	}

 

You will also see that it is creating a file PendingUsers_notifications 

In the default path of the blade files in resource/views

<li class="mb-2">
	<a class="dropdown-item border-radius-md" href="javascript:;">
		<div class="d-flex py-1">
			<div class="my-auto">
				<img src="{{ url('dashboard') }}/assets/img/kal-visuals-square.jpg" class="avatar avatar-sm  ms-3 ">
			</div>
			<div class="d-flex flex-column justify-content-center">
				<h6 class="text-sm font-weight-normal mb-1">
				<span class="font-weight-bold">New message</span> from Laur
				</h6>
				<p class="text-xs text-secondary ps-5 mb-0">
					<i class="fa fa-clock me-1"></i>
					13 minutes ago
				</p>
			</div>
		</div>
	</a>
</li>

You can modify it according to your needs