PHP code example of piscibus / notifly

1. Go to this page and download the library: Download piscibus/notifly library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

piscibus / notifly example snippets


return [
    'max_actors_count' => 2,
    'icons' => [
//        'verb' => VerbIcon::class
    ],
];
 



namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Piscibus\Notifly\Contracts\TransformableInterface;
use Piscibus\Notifly\Traits\Notifiable;

class User extends Authenticatable implements TransformableInterface
{
    use Notifiable;
}

use App\Notifications\CommentNotification;

$user->notify(new CommentNotification($actor, $object, $target));


use Illuminate\Database\Eloquent\Model;
use Piscibus\Notifly\Contracts\TransformableInterface;
use Piscibus\Notifly\Traits\Notifly;

class Comment extends Model implements TransformableInterface
{
    use Notifly;
}


use Piscibus\Notifly\Notifications\Notification;

class CommentNotification extends Notification
{
    /**
     * @var string
     */
    protected $verb = 'comment';
}


namespace App\Icons;
use Piscibus\Notifly\Notifications\Icon;

class CommentNotificationIcon extends Icon
{
     /**
         * Get notification icon attributes
         *
         * @return array
         */
        public function toArray(): array
        {
            return [
                'width' => 0,
                'height' => 0,
                'uri' => null,
            ];
        }
}

//configs/notifly.php
return [
// ..
    'icons' => [
         'comment' => CommentNotificationIcon::class,
    ]   
//    
];


$user = App\User::find(1);
foreach ($user->notifications as $notification){
    echo $notification->verb;
}

$user = App\User::find(1);
$bellCount = $user->unseenNotifications()->count();

foreach ($user->unseenNotifications as $notification){
     echo $notification->verb;
}

$user = App\User::find(1);
foreach ($user->unreadNotifications as $notification) {
    echo $notification->type;
}

$user = App\User::find(1);
foreach($user->unseenNotifications as $notificaion) {
    $notification->markAsSeen();
}

$user->unseenNotifications->markAsSeen();

$user = App\User::find(1);
$user->unseenNotifications()->update(['seen_at' => now()]);

$user->notifications()->delete();

$user = App\User::find(1);
foreach($user->notifications as $notification) {
    $readNotification = $notification->markAsRead();
}

$user = App\User::find(1);
foreach($user->readNotifications as $notification) {
    $notification->markAsUnRead();
}

Route::get('/notifications', function(){
    $user = App\User::find(1);
    $notifications = $user->jsonableNotifications;
    return JsonNotifications::collection($notifications);
})


namespace App;

use Illuminate\Database\Eloquent\Model;
use Piscibus\Notifly\Contracts\TransformableInterface;
use Piscibus\Notifly\Traits\Notifiable;
use App\Http\Resources\Comment as CommentResource;

class Comment extends Model implements TransformableInterface
{
     use Notifiable;
    
    /**
    * Gets the Eloquent API Resource
    **/
    public function getTransformer(): JsonResource
    {
        return new CommentResource($this);
    }
}
bash
 php artisan vendor:publish --provider="Piscibus\Notifly\NotiflyServiceProvider" --tag="migrations"
 php artisan migrate
 
bash
 php artisan vendor:publish --provider="Piscibus\Notifly\NotiflyServiceProvider" --tag="config"