All Projects → hmshafeeq → userstamps

hmshafeeq / userstamps

Licence: other
A simple package to insert and load userstamps for a model automatically, it provides an eloquent trait to use in models..

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to userstamps

Laravel Imageup
Auto Image & file upload, resize and crop for Laravel eloquent model using Intervention image
Stars: ✭ 646 (+1800%)
Mutual labels:  eloquent, trait
Laravel Ban
Laravel Ban simplify blocking and banning Eloquent models.
Stars: ✭ 572 (+1582.35%)
Mutual labels:  eloquent, trait
Befriended
Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.
Stars: ✭ 596 (+1652.94%)
Mutual labels:  eloquent, trait
Eloquent Sortable
Sortable behaviour for Eloquent models
Stars: ✭ 914 (+2588.24%)
Mutual labels:  eloquent, trait
Laravel Ownership
Laravel Ownership simplify management of Eloquent model's owner.
Stars: ✭ 71 (+108.82%)
Mutual labels:  eloquent, trait
Schedule
Schedule is a package that helps tracking schedules for your models. If you have workers in a company, you can set schedules for them and see their availability though the time.
Stars: ✭ 155 (+355.88%)
Mutual labels:  eloquent, trait
Laravel Likeable
Rate Eloquent models with Likes and Dislikes in Laravel. Development moved to Laravel Love package!
Stars: ✭ 95 (+179.41%)
Mutual labels:  eloquent, trait
laravel-cachable-attributes
Allows to cache attribute accessor values in an easy way.
Stars: ✭ 24 (-29.41%)
Mutual labels:  eloquent, trait
eloquent-has-by-join
Convert has() and whereHas() constraints to join() ones for single-result relations.
Stars: ✭ 21 (-38.24%)
Mutual labels:  eloquent
pimpable
No description or website provided.
Stars: ✭ 102 (+200%)
Mutual labels:  eloquent
query-filter
Define filters for your Eloquent models based on your request
Stars: ✭ 20 (-41.18%)
Mutual labels:  eloquent
magicproperties
A little but powerful package that allows you call getters and setters implicitly in PHP.
Stars: ✭ 13 (-61.76%)
Mutual labels:  trait
laravel-local-class-scope
A tiny macro that reuse a global scope class as a local scope
Stars: ✭ 16 (-52.94%)
Mutual labels:  eloquent
SlimREST
An app skeleton for building a REST API with the Slim PHP Micro-Framework
Stars: ✭ 22 (-35.29%)
Mutual labels:  eloquent
laravel-eloquent-relationships-gravit-designer
Graphic showing Laravel Eloquent ORM Relationships
Stars: ✭ 19 (-44.12%)
Mutual labels:  eloquent
eloquent-repository
Repository pattern for Eloquent ORM with focus in cache.
Stars: ✭ 30 (-11.76%)
Mutual labels:  eloquent
laravel-arangodb
ArangoDB driver for Laravel
Stars: ✭ 43 (+26.47%)
Mutual labels:  eloquent
laravel-repository
Repository pattern implementation for Laravel
Stars: ✭ 49 (+44.12%)
Mutual labels:  eloquent
laravel-hashid
HashId Implementation on Laravel Eloquent ORM
Stars: ✭ 23 (-32.35%)
Mutual labels:  eloquent
laravel-route-model-autobinding
THIS PACKAGE HAS BEEN DEPRECATED — Automatically bind Eloquent models as route segment variables.
Stars: ✭ 14 (-58.82%)
Mutual labels:  eloquent

Laravel Eloquent Userstamps

GitHub issues GitHub forks GitHub stars

A simple package to load & insert userstamps for a model

Requirements

  • This package requires PHP 5.6+
  • It works with Laravel 5.4 or later (and may work with earlier versions too).

Installation

Step 1: Install Through Composer

composer require velitsol/userstamps

Step 2: Add the Service Provider

// config/app.php

'providers' => [
    '...',
     VelitSol\Userstamps\UserstampServiceProvider::class
];

Usage

Load the trait in your model and see the magic.

Scenario 1 : Load Userstamps For A Model

You can configure this package to autoload the userstamp along with your model. This will be the case when userstamp is being set in controller or some where else manually.

use VelitSol\Userstamps\UserstampTrait;

class Post extends Model {

    use UserstampTrait;

    protected $userstamps = [
       'created_by',
       'updated_by',
       'submitted_by',
       'deleted_by'
    ];
}

And then you can autoload these userstamps like,

$posts = Post::withUserstamps()->get();

This will allow you to access the defined userstamps on your model as dynamic relationships

$post->createdByUser;
$post->updatedByUser;
$post->submittedByUser;
$post->deletedByUser;

Scenario 2 : Insert & Load Userstamps For A Model

You can configure this package to handle the userstamp insertion behind the scenes. This will also load those userstamps when you will fetch the records with eloquent. Auto insert will depend on,

  1. Event ('creating', 'saving', 'updating', 'deleting')
  2. Field
  3. Expression
use VelitSol\Userstamps\UserstampTrait;

class Post extends Model {

    use UserstampTrait;

    protected $userstamps = [
       // This userstamp should be set when 'creating' event is invoked.
       'created_by' => [
            'depends_on_event' => 'creating',
       ],
       // This userstamp should be set when 'creating' or 'updating' event is invoked.
       // This is an example, if a userstamp depends on multiple events
       'updated_by' => [
            'depends_on_event' => ['creating', 'updating'],
       ],
       'deleted_by' => [
             'depends_on_event' => 'deleting',
       ],

       // This userstamp should be set if "is_archived" is dirty (has some change in value)
       'archived_by' => [
            'depends_on_field' => 'is_archived'
       ],

       // This userstamp should be set if "updating" event is invoked on this model,
       // and "is_submitted" is dirty (has some change in value)
       'submitted_by'=> [
            'depends_on_event' => 'updating',
            'depends_on_field' => 'is_submitted'
       ],

       // This userstamp should be set if "updating" event is invoked on this model,
       // and provided expression evaluates to true
       'suspended_by' => [
          'depends_on_event' => 'updating',
          'depends_on_expression' => '$api_hits > 100' // $api_hits is a model field i.e $model->api_hits
       ],
       .............,
       ..............,
    ];
}

And then you can autoload these userstamps like,

$posts = Post::withUserstamps()->get();

This will allow you to access the defined userstamps on your model as dynamic relationships

$post->createdByUser;
$post->updatedByUser;
$post->archivedByUser;
$post->submittedByUser;
$post->suspendedByUser;

License

This open-source software is licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].