mardi 24 mai 2016

Review Schedule Task Code In Laravel 5.1

I am writing a code to be scheduled to run occasionally. I want to remove records of users who have their details on the users table but does not have their records in the profiles table as well. I am thinking about removing the by their id, but I am not sure how I can make the match. profiles migration:

public function up()
{
    Schema::create('profiles', function (Blueprint $table) {
        $table->increments('id');
        $table->timestamps();
        $table->string('gender',5);
        $table->integer('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); // When a profile is deleted- his corresponding associated id details are deleted as well.
        $table->tinyInteger('age')->unsigned()->nullable();
        $table->string('goals')->nullable();;
        $table->string('activityType')->nullable();
        $table->rememberToken(); // for remember me feature.
    });
}

Users migration:

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('username',20)->unique(); 
        $table->string('email')->unique();
        $table->string('password', 60);
        $table->rememberToken();
        $table->timestamps();
    });

I have started to write the query, yet I am not sure how to proceed.

 public function handle()
    {
    // type the query to get users that have no data in their profiles.

        $empty_profile=App\Profile:::where('id','')->get;
        $user_id=App\User::where('id')
    }

Appreciate your help. Thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire