nexxai

Solution Architect at Swoop Airlines

Member Since 1 Year Ago

Experience Points
22,540
Total
Experience

2,460 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
211
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 5
22,540 XP
Aug
16
3 months ago
Activity icon

Replied to Save Image From Remote URL

Have you tried adding "https:" to the from of the URL to see if it's related to a missing scheme?

Aug
15
3 months ago
Activity icon

Replied to Storage::assertMissing Failing; File Is Actually Gone In Real Life

That worked perfectly. Thank you so much!

Activity icon

Replied to Storage::assertMissing Failing; File Is Actually Gone In Real Life

I'm using Storage::fake('digitalocean'); at the top of the test though, so it's using the local storage for testing. It's the local (testing) storage where it fails; using the route normally (when it actually reaches out to DigitalOcean) works perfectly fine which is what makes no sense.

Activity icon

Started a new Conversation Storage::assertMissing Failing; File Is Actually Gone In Real Life

I have this test:

    public function deletingAStudioResultsInTheLogoBeingDeleted()
    {
        $this->signIn();

    Storage::fake('digitalocean');

        $studio = make(\App\Studio::class, [
            'name' => 'Fox Searchlight',
            'logo' => UploadedFile::fake()->image('fox-searchlight.jpg', 100, 100)->size(100),
        ]);

        $this->json('POST', route('studio.store'), $studio->toArray());

        // We want to first make sure it exists before we delete it, otherwise we might just be testing NULL
        Storage::disk('digitalocean')->assertExists('logos/fox-searchlight.jpg');

        $this->call('DELETE', route('studio.destroy', $studio));

        Storage::disk('digitalocean')->assertMissing('logos/fox-searchlight.jpg');
    }

testing this method:

    public function destroy(Studio $studio)
    {
        Storage::disk('digitalocean')->delete($studio->logo);

        $studio->delete();

        request()->session()->flash('success', 'Deleted '.$studio->name);

        return redirect()->route('studio.index');
    }

If I actually access this method through my browser, it correctly reaches out to DigitalOcean and deletes the logo. The problem is that if I run the test, I get:

> Executing task: /Users/user/.composer/vendor/bin/phpunit /Users/user/code/project/tests/Feature/StudioTest.php --filter '^.*::deletingAStudioResultsInTheLogoBeingDeleted( .*)?$' <

PHPUnit 7.5.14 by Sebastian Bergmann and contributors.

F                                                                   1 / 1 (100%)

Time: 729 ms, Memory: 28.00 MB

There was 1 failure:

1) Tests\Feature\StudioTest::deletingAStudioResultsInTheLogoBeingDeleted
Found unexpected file at path [logos/fox-searchlight.jpg].
Failed asserting that true is false.

/Users/user/code/project/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php:82
/Users/user/code/project/tests/Feature/StudioTest.php:316
/Users/user/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:201
/Users/user/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:160

FAILURES!
Tests: 1, Assertions: 2, Failures: 1.
The terminal process terminated with exit code: 1

Am I using the wrong assertion, or am I missing something?

Activity icon

Replied to How To Storage::fake() An Entire Set Of Tests

Ugh, I knew that. I'm an idiot.

Thanks!

Activity icon

Started a new Conversation How To Storage::fake() An Entire Set Of Tests

I have a class that an uploaded file is required and so I've added the UploadedFile::fake() to the factory, but I really don't want to be uploading actual files to the host for every test (there are a lot of tests) and so I want to mock the Storage. The Laravel docs say to use "Storage::fake()" which makes sense but I don't want to have to add that to every test and so I was hoping to use it in the __construct method like:

<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Foundation\Testing\RefreshDatabase;

class StudioTest extends TestCase
{
    use RefreshDatabase;

    public function __construct()
    {
        Storage::fake('storage_location');
    }

but when I do, I get this error:

PHP Fatal error:  Uncaught ReflectionException: Class path.storage does not exist in /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php:790
Stack trace:
#0 /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php(790): ReflectionClass->__construct('path.storage')
#1 /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php(667): Illuminate\Container\Container->build('path.storage')
#2 /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php(615): Illuminate\Container\Container->resolve('path.storage', Array)
#3 /Users/path/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(121): Illuminate\Container\Container->make('path.storage', Array)
#4 /Users/path/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(846): app('path.storage')
#5 /Users/path/vendor/laravel/framework/src/Illuminate/Support/Facades/Storage.php(26): in /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 790

Fatal error: Uncaught ReflectionException: Class path.storage does not exist in /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php:790
Stack trace:
#0 /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php(790): ReflectionClass->__construct('path.storage')
#1 /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php(667): Illuminate\Container\Container->build('path.storage')
#2 /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php(615): Illuminate\Container\Container->resolve('path.storage', Array)
#3 /Users/path/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(121): Illuminate\Container\Container->make('path.storage', Array)
#4 /Users/path/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(846): app('path.storage')
#5 /Users/path/vendor/laravel/framework/src/Illuminate/Support/Facades/Storage.php(26): in /Users/path/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 790

which I assume has something to do with the fact that Storage:: is just a facade, but I don't know enough PHP to know what to do about it or even the right terms to Google.

Can anyone help me out?

Aug
11
4 months ago
Activity icon

Replied to Str Slug With Arabic Not Working

Also, this would be a great place to contribute to the Laravel framework, by adding support for Arabic to the slug generator

Aug
01
4 months ago
Activity icon

Replied to Not Saving To Database

@aurawindsurfing Looks like you got it right. I'm not sure why it worked fine in tinker but not via http, but regardless, adding the $pipeline->save() to the controller worked.

Thanks so much for your help!

Activity icon

Replied to Not Saving To Database

Here's a wrinkle: it works fine when I use artisan tinker.

@aurawindsurfing - I'll try your method and report back in a moment.

Activity icon

Replied to Not Saving To Database

I only have the one database and schema on this machine, and I've confirmed that even by closing and re-opening TablePlus that the table is completely empty. I also use this database for sessions and those are persisting properly.

Activity icon

Replied to Not Saving To Database

Also, if I update the $this->save() to dd($this->save());, it returns true. So it obviously thinks it's saving correctly, but for whatever reason, the DB isn't actually doing it.

Activity icon

Started a new Conversation Not Saving To Database

I have this model/methods:

<?php

namespace App;

use Illuminate\Support\Arr;
use Illuminate\Database\Eloquent\Model;
use App\Http\Requests\PipelineRequest;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Auth;

class Pipeline extends Model
{
    use SoftDeletes;

    protected $guarded = [];

    /**
     * Create a single API key
     *
     * @return string
     */
    public static function generate_api_key()
    {
        $randomness = random_bytes(256);
        $key = urlencode(hash('sha256', $randomness));

        return $key;
    }

    public function ingest($row, $schema_id)
    {
        $this->name = $row[0];
        $this->table_name = $row[0];
        $this->created_by_user_id = Auth::id();
        if (!$this->api_key_primary) {
            $this->api_key_primary = Pipeline::generate_api_key();
        }
        if (!$this->api_key_secondary) {
            $this->api_key_secondary = Pipeline::generate_api_key();
        }
        $this->dependsOn_azure_data_pipeline_activity_name = 'ETL Log and Load';
        $this->callback_url = null;
        $this->modified_column_name = $row[1];
        if (Arr::exists($row, 2)) {
            $this->version_table_name = $row[2];
        }
        $this->schema_id = $schema_id;

        $this->save();
        dd($this);
    }
}

When I hit the Pipeline::ingest route with the appropriate data, it does spit out a result:

Pipeline {#727 ▼
  #guarded: []
  #connection: "mysql"
  #table: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: true
  #attributes: array:13 [▶]
  #original: array:13 [▼
    "name" => "Equipment"
    "table_name" => "Equipment"
    "created_by_user_id" => 5
    "api_key_primary" => "6bf0cc9129525b02cfd4a4de794d4323d4c255451143da79cc6be87b98951815"
    "api_key_secondary" => "163dfb8087594a0377e4be3cbec6a6dd99a22d8d5ab9d852488113ef421df182"
    "dependsOn_azure_data_pipeline_activity_name" => "ETL Log and Load"
    "callback_url" => null
    "modified_column_name" => "ModifiedUTC"
    "version_table_name" => "08d84af1816ebc474ef4c5e4dbfe6841abb042c46103965b3940f46fc51bd731"
    "schema_id" => "3"
    "updated_at" => "2019-08-01 17:36:43"
    "created_at" => "2019-08-01 17:36:43"
    "id" => 232
  ]
  #changes: []
  #casts: []
  #dates: array:1 [▶]
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #fillable: []
  #forceDeleting: false
}

with even the id value incrementing every single time, but nothing is actually persisted to the database. I feel like I'm taking crazy pills here.

Can anybody see what I'm missing?