flyingL123

flyingL123

Member Since 1 Year Ago

Experience Points 12,580
Experience
Level
Lessons Completed 123
Lessons
Completed
Best Reply Awards 0
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.

07 Jan
1 week ago

flyingL123 left a reply on Bucket Name Not Appearing In S3 Url

@REALRANDYALLEN - Interesting, that works. However, I'm using laravel-paperclip and removing that results in an error:

RuntimeException with message 'Could not determine base URL for storage disk 'paperclip'

It looks like even though Laravel doesn't require it, paperclip does.

06 Jan
1 week ago

flyingL123 started a new conversation Bucket Name Not Appearing In S3 Url

I'm confused. I'm using Laravel 5.6, and I entered my s3 config details like so:

AWS_ACCESS_KEY_ID=MY_KEY
AWS_SECRET_ACCESS_KEY=MY_SECRET
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=mybucket
AWS_URL=https://s3.amazonaws.com

I'm able to upload files correctly. They go to the right bucket. However, when I get a URL for a file on the s3 disk, it doesn't include the bucket in the URL.

echo Storage::disk('s3')->url('path/to/a/file.jpg');

// https://s3.amazonaws.com/path/to/a/file.jpg

Instead, I find that I need to include the bucket in the AWS_URL variable, like this:

AWS_URL=https://s3.amazonaws.com/mybucket

This results in the correct URLs, but is that expected? Do I need to include the bucket in that URL? I thought it was supposed to be included automatically by the framework when generating the URL.

Am I filling these variables out correctly?

I appreciate the help!

31 Dec
2 weeks ago

flyingL123 left a reply on Is There A Shorthand To Schedule Commands To Be Queued?

@SNAPEY - Ok, that makes sense, but I am still confused about one thing. If the command queues the job, is there any way for me to run the logic in the Job without hitting the queue. If I want to go to the command line and manually run the command with artisan, how can I set it up so the command doesn't always hit the queue, but instead just runs the code in the current process?

Should I add a 'queue' option to the command, and maybe have the default set to 'sync', so it runs immediately if no queue is specified?

flyingL123 left a reply on Is There A Shorthand To Schedule Commands To Be Queued?

@OHFFS - I could, but then I still have a command and a job doing the exact same thing. I was under the impression the command could just be queued, which is why the Artisan::queue() method and the Illuminate\Foundation\Console\QueuedCommand class exist.

flyingL123 left a reply on Is There A Shorthand To Schedule Commands To Be Queued?

@SNAPEY - In my case, I have written a command to export some data to an FTP service. Something like php artisan data:export. I want it to be a command so that I can call it manually from the command line when needed (in the same process, not in the background). However, it will mostly be called on a schedule, and sometimes there are errors with the connection. So I wanted to queue the command so it will be retried if there are errors.

What's the best way to do this? I didn't want to create a Job class whose purpose was to trigger the command with Artisan::call(). Maybe I am not thinking about this correctly.

flyingL123 left a reply on Is There A Shorthand To Schedule Commands To Be Queued?

@_STEFANZWEIFEL - Hmmm, I don't think that's the case. I think it may just be confusing documentation. Because when I run Artisan::queue('command:name');, I see an instance of Illuminate\Foundation\Console\QueuedCommand pushed onto the queue.

Also, as you can see in the docs the the onQueue and onConnection methods can be chained to the call to Artisan::queue():

Artisan::queue('email:send', [
    'user' => 1, '--queue' => 'default'
])->onConnection('redis')->onQueue('commands');

flyingL123 started a new conversation Is There A Shorthand To Schedule Commands To Be Queued?

I can schedule artisan commands like this:

$schedule->command('emails:send --force')->daily();

I can schedule a queue job like this:

$schedule->job(new Heartbeat)->everyFiveMinutes();

I can queue and artisan command like this:

Artisan::queue('email:send', [
    'user' => 1, '--queue' => 'default'
]);

But, from what I can tell, there is no way to nicely schedule a queued artisan command. In other words, I can accomplish what I need like this:

$schedule->call(function () {
    Artisan::queue('command:name');
})->everyMinute();

But it seems like there should be a better way. Is there any way to use the $schedule->job() method, but pass it a command name?

12 Jun
7 months ago

flyingL123 left a reply on Creating And Dropping A Table During Test Breaks RefreshDatabase Trait

Making the stubs table temporary did the trick. Creating a table causes an implicit commit in mysql. Creating a temporary table does not. It also means I don't need to drop the table either, since it happens automatically:

Schema::create('stubs', function ($table) {
    $table->temporary()
    $table->increments('id');
    $table->string('name');
    $table->timestamps();
});

Seems to be working perfectly so far.

flyingL123 started a new conversation Creating And Dropping A Table During Test Breaks RefreshDatabase Trait

I've created a trait using in my Laravel 5.6 app. The trait is called Projectable. This trait is meant to be used by Eloquent models. In order to test the trait, I wanted to create a ProjectableStub model to use in the tests. However, since this is an Eloquent model, it requires a table.

I wanted to simply create and drop a table just for testing. However, when I do this, it seems like something breaks regarding the RefreshDatabase functionality. To demonstrate, I am simply running two tests, both of which try to create a Product model with id = 1. Since the RefreshDatabase trait is being used, this should work fine. And, in the example below, it does:

    <?php
    
    namespace Tests\Feature;
    
    use App\Product;
    use Tests\TestCase;
    use App\Concerns\Projectable;
    use Illuminate\Support\Facades\Schema;
    use Illuminate\Foundation\Testing\WithFaker;
    use Illuminate\Foundation\Testing\RefreshDatabase;
    use Illuminate\Database\Eloquent\Model as Eloquent;
    
    class ProjectableTest extends TestCase
    {
        use RefreshDatabase;
    
        public function setUp()
        {
            parent::setUp();
    
            //$this->createStubTable();
        }
    
        /**
         * @test
         */
        public function example_first_test()
        {
            factory(Product::class)->create(['id' => 1]);
        }
    
        /**
         * @test
         */
        public function example_second_test()
        {
            factory(Product::class)->create(['id' => 1]);
        }
    
        public function tearDown()
        {
            //$this->dropStubTable();
    
            parent::tearDown();
        }
    
        private function createStubTable()
        {
            Schema::create('stubs', function ($table) {
                $table->increments('id');
                $table->string('name');
                $table->timestamps();
            });
        }
    
        private function dropStubTable()
        {
            Schema::dropIfExists('stubs');
        }
    }

    class ProjectableStub extends Eloquent
    {
        use Projectable;
    
        protected $table = 'stubs';
    
        protected $guarded = [];
    }

However, as soon as I uncomment the two lines so that the stubs table is created and dropped, I get a SQL error that a duplicate ID is being used:

    <?php
    
    namespace Tests\Feature;
    
    use App\Product;
    use Tests\TestCase;
    use App\Concerns\Projectable;
    use Illuminate\Support\Facades\Schema;
    use Illuminate\Foundation\Testing\WithFaker;
    use Illuminate\Foundation\Testing\RefreshDatabase;
    use Illuminate\Database\Eloquent\Model as Eloquent;
    
    class ProjectableTest extends TestCase
    {
        use RefreshDatabase;
    
        public function setUp()
        {
            parent::setUp();
    
            $this->createStubTable();
        }
    
        /**
         * @test
         */
        public function example_first_test()
        {
            factory(Product::class)->create(['id' => 1]);
        }
    
        /**
         * @test
         */
        public function example_second_test()
        {
            factory(Product::class)->create(['id' => 1]);
        }
    
        public function tearDown()
        {
            $this->dropStubTable();
    
            parent::tearDown();
        }
    
        private function createStubTable()
        {
            Schema::create('stubs', function ($table) {
                $table->increments('id');
                $table->string('name');
                $table->timestamps();
            });
        }
    
        private function dropStubTable()
        {
            Schema::dropIfExists('stubs');
        }
    }

    class ProjectableStub extends Eloquent
    {
        use Projectable;
    
        protected $table = 'stubs';
    
        protected $guarded = [];
    }
  1. Tests\Feature\ProjectableTest::example_second_test Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'PRIMARY'

Does anyone know why creating and dropping a table within the test is causing this issue? Is there a better way to go about this? Maybe some way to add a migration at runtime for this new table?

12 Mar
10 months ago

flyingL123 left a reply on Best Practice For Developing A Site That Uses 3rd Party APIs

@shez1983 I guess what I'm trying to say is that there isn't actually any real data to fetch because I'm seeding the database with fake information. In production, objects in my database would correspond to real objects in BigCommerce, so the API calls will make sense and work, however, during development, making these API calls doesn't make sense because the corresponding objects don't exist in BigCommerce.

One option that makes sense to me would be to create a 'fake' BigCommerce class that just uses sub function to return fake data. I understand how to do this during tests, by creating mocks and binding to the container during the test or even in a setUp method.

But how would I do this same thing during development?

flyingL123 started a new conversation Best Practice For Developing A Site That Uses 3rd Party APIs

What is the best way to handle developing an app that accesses 3rd-party apis? For example, I have an app that relies on data from the BigCommerce API. Every time a certain route is loaded, a call is made to using a 3rd party BigCommerce library to hit their API. For example,

public function view(Store $store)
{
    $bcStore = Bigcommerce::getStore($store->id);

    // Do some stuff with the data before returning the view

    return view('stores.view');
}

As I am developing this app I am obviously loading this route many times in a browser, which means I'm making an continuously hitting the BigCommerce servers. Additionally, the data I seed my database with for developing is not for real BigCommerce stores, so these continuous calls to the BigCommerce server are all going to fail.

What is the best practice for this sort of situation? During testing I know I can create mocks and use the Service Container to bind the mocks rather than the real classes. Am I supposed to do the same thing for development? If so, where and how do I do this?

Just trying to understand what my options are. This seems like a pretty common thing but I'm struggling to figure out the "right" way to handle it.