PHP code example of inpin / lara-alert

1. Go to this page and download the library: Download inpin/lara-alert 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/ */

    

inpin / lara-alert example snippets


'providers' => [
    \Inpin\LaraAlert\LaraAlertServiceProvider::class,
],

class Book extends \Illuminate\Database\Eloquent\Model {
    use Inpin\LaraAlert\Alertable;
}

// Create an alert with type of 'alert' by currently logged in user without description.
$book->createAlert();

// Create a alert on $book object with type of "some-alert-type", and null description.
$book->createAlert('some-alert-type');

// Create a alert on $book object with type of "some-alert-type", null description,
// and current logged in user form 'api' guard as owner.
$book->createAlert('some-alert-type', 'api');

// Create a alert on $book object with type of "some-alert-type", null description, and $user as owner.
$book->createAlert('some-alert-type', $user);

// Create a alert on $book object with type of "some-alert-type", with description of "some message,
// and current logged in user form 'api' guard as owner.
$book->createAlert('some-alert-type', 'api', 'some message');

// Create a alert on $book object with type of "some-alert-type", with description of "some message,
// and current logged in user form 'api' guard as owner.
$book->createAlert('some-alert-type', $user, 'some message');

// Create a alert on $book object with "alert item id" of 1 and 2, put user message of "some message on it",
// and put $user (3rd param) as alerter.
$book->createAlert([1, 2], 'some message', $user');

$book->alerts(); // HasMany relation to alerts of book.
$book->alerts; // Collection of book's alerts.

$book->isAlertedBy() // check if current logged in user form default guard has alerted book.
$book->isAlertedBy('api') // check if current logged in user form 'api' guard has alerted book.
$book->isAlertedBy($user) // check if '$user' has alerted book.

$book->isAlerted() // check if $book has alert.
$book->isAlerted // check if $book has alert.

$book->alertsCount; // return number of alerts on $book.
$book->alertsCount(); // return number of alerts on $book.

// set seen_at with current timestamp.
$alert->seen();

// check if $alert is new or not.
$alert->isNew();
$alert->isNew;

// check if $alert is seen or not.
$alert->isSeen();
$alert->isSeen;
bash
php artisan vendor:publish --provider="Inpin\LaraAlert\LaraAlertServiceProvider" --tag=migrations
php artisan migrate