Skip to content

A simple way to generate the model's author user when created

Notifications You must be signed in to change notification settings

binarycabin/laravel-author

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Laravel-Author

A simple way to generate the model's author user when created

composer require binarycabin/laravel-author

This package adds a very simple trait to automatically save the user id who created this model.

Simply add the "\BinaryCabin\LaravelAuthor\Traits\HasAuthorUser;" trait to your model:

<?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":

protected $authorUserIdFieldName = 'user_id';

This trait also provides a relationship:

dump($project->authorUser)

and query scope:

dump(\App\Project::byAuthorUser($userId)->get());

About

A simple way to generate the model's author user when created

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages