dev-master
9999999-devA simple way to generate the model's author user when created
MIT
by Jeff Kilroy
Wallogit.com
2017 © Pedro Peláez
A simple way to generate the model's author user when created
A simple way to generate the model's author user when created, (*1)
composer require binarycabin/laravel-author
This package adds a very simple trait to automatically save the user id who created this model., (*2)
Simply add the "\BinaryCabin\LaravelAuthor\Traits\HasAuthorUser;" trait to your model:, (*3)
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
use \BinaryCabin\LaravelAuthor\Traits\HasAuthorUser;
}
If your column name is not "author_user_id", simply add a new property to your model named "authorUserIdFieldName":, (*4)
protected $authorUserIdFieldName = 'user_id';, (*5)
This trait also provides a relationship:, (*6)
dump($project->authorUser)
and query scope:, (*7)
dump(\App\Project::byAuthorUser($userId)->get());
A simple way to generate the model's author user when created
MIT