PHP code example of jeffersongoncalves / laravel-created-by
1. Go to this page and download the library: Download jeffersongoncalves/laravel-created-by library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jeffersongoncalves / laravel-created-by example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use JeffersonGoncalves\CreatedBy\Models\Concerns\WithCreatedBy;
use JeffersonGoncalves\CreatedBy\Models\Concerns\WithUpdatedBy;
use JeffersonGoncalves\CreatedBy\Models\Concerns\WithDeletedBy;
use JeffersonGoncalves\CreatedBy\Models\Concerns\WithRestoredBy;
use JeffersonGoncalves\CreatedBy\Models\Concerns\WithRestoredAt;
class Post extends Model
{
use SoftDeletes;
use WithCreatedBy;
use WithUpdatedBy;
use WithDeletedBy;
use WithRestoredBy;
use WithRestoredAt;
}
return [
// The authentication guard used to resolve the current user (null = default guard).
'guard' => null,
// The column names used to store the audit information.
'columns' => [
'created_by' => 'created_by',
'updated_by' => 'updated_by',
'deleted_by' => 'deleted_by',
'restored_by' => 'restored_by',
'restored_at' => 'restored_at',
],
];
// Filter by the user id stored in the column
Post::query()->createdBy($userId)->get();
Post::query()->updatedBy($userId)->get();
Post::query()->deletedBy($userId)->get();
Post::query()->restoredBy($userId)->get();
// Eager load the related user relationship
Post::query()->withCreatedBy()->get();
Post::query()->withUpdatedBy()->get();
Post::query()->withDeletedBy()->get();
Post::query()->withRestoredBy()->get();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.