sqits / laravel-userstamps

Package to maintain the users who created, updated and deleted eloquent models
MIT License
18 stars 7 forks source link

dont active the event and not register at field created_by #3

Closed cirelramos closed 5 years ago

cirelramos commented 5 years ago
<?php

return [

    /*
     * Define the table which is used in de database to retrieve the users
     */

    'users_table' => 'users',

    /*
     * Define the mmodel which is used for the relationships on your models
     */

    'users_model' => App\HR\Auth\Users\User::class,

    /*
     * Define the column which is used in de database to save the user's id
     * which created the model.
     */

    'created_by_column' => 'created_by',

    /*
     * Define the column which is used in de database to save the user's id
     * which updated the model.
     */

    'updated_by_column' => 'updated_by',

    /*
     * Define the column which is used in de database to save the user's id
     * which deleted the model.
     */

    'deleted_by_column' => 'deleted_by',

];
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTableActionPlans extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create( 'action_plans', function ( Blueprint $table ) {
                $table->increments( 'id_action_plan' );
                $table->string( 'name', 160 );
                $table->string( 'description', 220 );
                $table->integer( 'archived' );
                $table->integer( 'history' );
                $table->integer( 'status' );
                $table->timestamps();
                $table->softDeletes();
                $table->userstamps();
                $table->softUserstamps();
            }
        );
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists( 'action_plans' );
    }
}
<?php

namespace App\HR\Metrics\ActionPlans;

use Illuminate\Database\Eloquent\Model;
use Sqits\UserStamps\Concerns\HasUserStamps;

/**
 * @property varchar                                  $name             name
 * @property varchar                                  $description      description
 * @property timestamp                                $created_at       created at
 * @property timestamp                                $updated_at       updated at
 * @property timestamp                                $deleted_at       deleted at
 * @property \Illuminate\Database\Eloquent\Collection $shasambassador   belongsToMany
 * @property \Illuminate\Database\Eloquent\Collection $shastask         belongsToMany
 * @property \Illuminate\Database\Eloquent\Collection $dimensionshass   belongsToMany
 * @property \Illuminate\Database\Eloquent\Collection $employeeshastask belongsToMany
 * @property \Illuminate\Database\Eloquent\Collection $measurehass      belongsToMany
 */
class ActionPlan extends Model
{

    use HasUserStamps;
    /**
     * Database table name
     */
    protected $table      = 'action_plans';
    protected $primaryKey = 'id_action_plan';

    /**
     * Mass assignable columns
     */
    protected $fillable
        = [
            'name',
            'archived',
            'history',
            'description',
            'status',
        ];

    /**
     * Date time columns.
     */
    protected $dates = [];

}
    public function store( StorePlanRequest $request)
    {
        $modelActionPlan = new ActionPlan();
        $modelActionPlan->fill($request->all());
        $modelActionPlan->save();

    } /**

save the register but not register the user :/ i check with debug a break-point the method and never stop the break-point :S

NOTE: created good the table with field and relations but dont register user

rschaaphuizen commented 5 years ago

Could you send me the migrations file of the users table you're using?

cirelramos commented 5 years ago
<?php

use App\HR\Auth\Users\User;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->string('verified');
            $table->string('verification_token')->nullable();
            $table->string('admin');
            $table->timestamps();
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}
cirelramos commented 5 years ago

model

<?php

namespace App\HR\Auth\Users;

use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Traits\TextConverter;

/**
 * @property int            $id_role
 * @property string         $first_name
 * @property string         $last_name
 * @property string         $second_last_name
 * @property string         $full_name
 * @property string         $profile_picture
 * @property string         $email
 * @property bool           $verified
 * @property string         $password
 * @property string         $verification_token
 * @property bool           $first_time_verification
 * @property \Carbon\Carbon $verification_token_created_at
 * @property string         $admin
 * @property int            $id_gender
 */
class User extends Authenticatable
{
    use Notifiable, HasApiTokens, SoftDeletes, TextConverter;

    protected $table = 'users';
    protected $dates = ['deleted_at'];
    public $userPictureProfile;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'id_role',
        'first_name',
        'last_name',
        'second_last_name',
        'full_name',
        'profile_picture',
        'email',
        'verified',
        'password',
        'verification_token',
        'first_time_verification',
        'verification_token_created_at',
        'admin',
        'id_gender',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'remember_token',
        'verification_token',
    ];

}
rschaaphuizen commented 5 years ago

The migration of your users table is using a normal integer field for the id of the user

$table->increments('id')

The migrations of the userstamps is using the bigIncrements function to work with the recent version of Laravel. You should add the following to your configuration file:

    /*
     * Define the table column type which is used in the table schema for
     * the id of the user
     */

    'users_table_column_type' => 'increments',

Please let me know if it works after that. Aren't you receiving an error while migrating?

cirelramos commented 5 years ago

I made the modifications and I have no errors, but I will create a new project with the version of Laravel that I use to do tests and I tell you

cirelramos commented 5 years ago

sorry not to respond quickly, you can verify in a project from scratch that I have created, to verify that it is missing ?, thanks in advance, I will leave you the repository link, Apology not respond quickly, you can check in a project that I created from scratch to check missing ?, thanks in advance, I'll leave the link repository

https://github.com/cirelramos/test-userstamps

rschaaphuizen commented 5 years ago

I've found the bug in the package and just released a new version 0.0.4 where the bug has been fixed. I've made a pull request for your example with the corrections/changes in the config file.

I also added a default user in the seeder to have the user quickly available while testing through Tinker. Please let me know if you still have problems using our package.

cirelramos commented 5 years ago

I've found the bug in the package and just released a new version 0.0.4 where the bug has been fixed. I've made a pull request for your example with the corrections/changes in the config file.

I also added a default user in the seeder to have the user quickly available while testing through Tinker. Please let me know if you still have problems using our package.

yeah it is correct, working perfectly, thanks bro