alhoqbani

alhoqbani

Member Since 1 Year Ago

Experience Points 67,230
Experience
Level
Lessons Completed 660
Lessons
Completed
Best Reply Awards 1
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

13 Nov
1 year ago

alhoqbani left a reply on .htaccess On Root Directory To Redirect To Public Folder

When you create the subdomain set the document root to public_html/panel/public

No need to change the .htaccess

09 Jul
1 year ago

alhoqbani left a reply on Eloquent Won't Return What Is In The Database

@leecjeffries Yes. You maybe provide an option for the user to store more multiple pictures and switch between them. In this case will use one-to-many.

alhoqbani left a reply on Eloquent Won't Return What Is In The Database

@leecjeffries

It depends on your app design and your requirements. Yes, usually a user has a single profile picture, and each profile picture belongs to a single user. In this case will use one-to-one relationship.

// User.php 
public function profilePictures()
{
    return $this->hasOne(ProfilePicture::class);
}

// ProfilePicture.php

public function user()
{
    return $this->belongsTo(User::class); //
}

In profile_pictures table, you will have a column user_id.

alhoqbani left a reply on Eloquent Won't Return What Is In The Database

You need to return the relationship in your method

public function profile_picture()
{
    return $this->hasMany(ProfilePicture::class);
}

28 May
1 year ago

alhoqbani left a reply on Since Laravel Mix PhpStorm Become Slow When Watch Is Running

Try excluding the public folder from indexing.

09 Apr
1 year ago

alhoqbani left a reply on Changing Default Disk For Testing.

I think I found a workaround for this issue:

I changed the default disk in config/filesystems.php

'default' => env('DISK_TESTING', 'local'),

and in phpunit.xml added this line:

<env name="DISK_TESTING" value="avatars"/>

finally, in tests/TestCase.php

    protected function setUp()
    {
        parent::setUp();
        // Create The fake Disk
        Storage::fake('avatars');
    }
02 Apr
1 year ago

alhoqbani left a reply on BadMethodCallException: Method SeeJson Does Not Exist.

it should be:

        $this->json('GET', '/api/weight/getWeight/23/232')
            -> assertJson([
               'created' => true
            ]);

alhoqbani started a new conversation Changing Default Disk For Testing.

I'm trying to build a test for images handling in my application. For the database testing I'm using DatabaseMigrations, so the test persists records in sqlite memory and then discard them after the test.

Is there a way to achieve equivalent results when testing file handling (uploading and deleting files).

Right now I'm using the fake method as suggested per the docs:

        Storage::fake('avatars');

        $response = $this->json('POST', '/avatar', [
            'avatar' => UploadedFile::fake()->image('avatar.jpg')
        ]);

        // Assert the file was stored...
        Storage::disk('avatars')->assertExists('avatar.jpg');

        // Assert a file does not exist...
        Storage::disk('avatars')->assertMissing('missing.jpg');

However in my Image model, i'm overriding the delete() method to delete the file linked to the record:

    public function delete()
    {
        Storage::delete($this->image_path);

        return parent::delete();
    }

When testing this method, it will always fail because this method will delete files only from the default storage, but not from the fake storage ('avatars').

Here is my test:

/** @test */
    public function deleted_image_from_db_will_delete_the_file()
    {
        Storage::fake('avatars');
        $file = UploadedFile::fake()->image('avatar.png');
        $image = Image::fromForm($file);  // Store the image and set image_path;
        $image->product_id = 1;
        $image->save();

        Storage::disk('avatars')->assertExists($image->image_path);
        $image->delete();
        Storage::disk('avatars')->assertMissing($image->image_path);
    }

Is it possible to set the default disk for testing to a fake storage?