2017 © Pedro Peláez
 

package lara-alert

Add Alertable trait to Laravel Eloquent models

image

inpin/lara-alert

Add Alertable trait to Laravel Eloquent models

  • Wednesday, June 13, 2018
  • by enourinick
  • Repository
  • 1 Watchers
  • 3 Stars
  • 85 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

LaraAlert

Build Status StyleCI Maintainability Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Trait for Laravel Eloquent models to allow easy implementation of a "user alerts" feature., (*2)

Composer Install (for Laravel 5.5 and above)

composer require inpin/lara-alert

Install and then run the migrations

'providers' => [
    \Inpin\LaraAlert\LaraAlertServiceProvider::class,
],
php artisan vendor:publish --provider="Inpin\LaraAlert\LaraAlertServiceProvider" --tag=migrations
php artisan migrate

Model and database schema

it will create you a table of laraalert_alerts with following fields:, (*3)

type is the type of alert, ex: 'alert', 'confirmation complete', 'software update, etc., (*4)

description a nullable text which describe alert., (*5)

seen_at determines if current alert is new (seen_at is null_) or not (seen_at fills with timestamp), (*6)

Setup your models

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

Sample Usage

// 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.

Alert objects, (*7)

// 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;

Credits

  • Mohammad Nourinik - http://inpinapp.com

The Versions

13/06 2018

dev-master

9999999-dev

Add Alertable trait to Laravel Eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mohammad Nourinik

laravel eloquent trait laravel5 notification push store alert alertable push-notify

13/06 2018

1.0.2

1.0.2.0

Add Alertable trait to Laravel Eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mohammad Nourinik

laravel eloquent trait laravel5 notification push store alert alertable push-notify

05/06 2018

1.0.1

1.0.1.0

Add Alertable trait to Laravel Eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mohammad Nourinik

laravel eloquent trait laravel5 notification push store alert alertable push-notify

04/06 2018

1.0.0

1.0.0.0

Add Alertable trait to Laravel Eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mohammad Nourinik

laravel eloquent trait laravel5 notification push store alert alertable push-notify