alhoqbani

Experience

54,580

1 Best Reply Awards

  • Member Since 1 Year Ago
  • 537 Lessons Completed
  • 11 Favorites

13th November, 2017

alhoqbani left a reply on .htaccess On Root Directory To Redirect To Public Folder • 7 months ago

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

No need to change the .htaccess

9th July, 2017

alhoqbani left a reply on Eloquent Won't Return What Is In The Database • 11 months ago

@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 • 11 months ago

@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 • 11 months ago

You need to return the relationship in your method

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

28th May, 2017

alhoqbani left a reply on Since Laravel Mix PhpStorm Become Slow When Watch Is Running • 1 year ago

Try excluding the public folder from indexing.

9th April, 2017

alhoqbani left a reply on Changing Default Disk For Testing. • 1 year ago

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');
    }

2nd April, 2017

alhoqbani left a reply on BadMethodCallException: Method SeeJson Does Not Exist. • 1 year ago

it should be:

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

alhoqbani started a new conversation Changing Default Disk For Testing. • 1 year ago

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?

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.