binarycabin/laravel-author

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

Installs: 54

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/binarycabin/laravel-author

1.0.0 2017-11-14 11:39 UTC

This package is auto-updated.

Last update: 2025-10-06 12:31:36 UTC


README

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());