dericcain

dericcain

Member Since 3 Years Ago

Experience Points 20,370
Experience Level 5

4,630 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 194
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.

12 Feb
2 years ago

dericcain started a new conversation Mock Request() Global Helper

I have a test that creates a user in Stripe. In order to do this, I am using the request() helper because of it's convenience. This is what my create method looks like to create the Stripe customer:

public function create()
    {
        return Customer::create([
            'description' => request('lastName') . ', ' . request('firstName'),
            'email' => request('email'),
            'source' => request('token'),
            'metadata' => [
                'first_name' => request('firstName'),
                'last_name' => request('lastName'),
                'address' => request('address'),
                'zip' => request('zip'),
                'phone' => request('phone'),
            ]
        ], ['api_key' => config('services.stripe.secret')]);
    }

This is not in the controller, but in its own class called StripeCustomer. This would be a unit test because it is part of a series of events that happens when a donation is posted, otherwise I would test it using $this->post()...

So, how can I mock the global request so that I can add the fields necessary to test my method?

07 Feb
2 years ago

dericcain left a reply on Laravel Mix With HMR

Yep, me too. I must say, I am disappointed in Laravel Mix. If I was building SPA's then I could see the benefits. However, since day 1 I have been running into issues with it and it doesn't live reload php. It just seems like we've taken a step back on this one, which is out of the ordinary for anything Laravel.

13 Oct
2 years ago

dericcain started a new conversation Eloquent Relationship Chaining Problem

I have something called a FreeLook that can have a SignVendor and a PaintVendor. The SignVendor or PaintVendor can have a VendorJob using polymorphic relations. The vendors can have many jobs. I want to get the job for the FreeLook for a specific type of vendor. But.. when I do this..

FreeLook::find(1)->signVendor->jobs` 

I get an array because the vendor can have many jobs … and it’s not the job that is associated with the he `Free, it’s all of the jobs for that vendor.

So, I do I make this relationship so that I can get the particular job for a specific vendor type for a freelook?

11 Oct
2 years ago

dericcain started a new conversation Using MorphMap On More Than One Polymorphic Relationship

I have a couple of models SignVendor and PaintVendor, which have quite a few different relationships with other models. For instance:

VendorLinks

  • vendor_id (the id of the vendor)
  • vendor_type (the type of vendor, i.e. SignVendor or PaintVendor)

-- and --

Quotes

  • vendor_id (the id of the vendor)
  • vendor_type (the type of vendor, i.e. SignVendor or PaintVendor)

-- and --

Reviews

  • vendor_id (the id of the vendor)
  • vendor_type (the type of vendor, i.e. SignVendor or PaintVendor)

Instead of storing the fully qualified class name in my database, I want to use the Relation::morphMap, but how should I define them? Right now, I am calling them like so in my AppServiceProvider, but this does not seem to be working.

Relation::morphMap([
     'paint' => App\Models\FreeLook\PaintVendor::class,
     'sign' => App\Models\FreeLook\SignVendor::class,
]);

If I place a dd('Here') as one of the values within the morphMap method, execution does stop, so I know that the map is getting called. I can't figure out why when I persist data, the fully qualified class name is still being persisted in the vendor_type field.

29 Sep
2 years ago

dericcain started a new conversation Best Way To Compile JS Files That Are Only Used On One Page

So that my setup runs slim, I am using one JS file per group of pages (think users.js will cover all of the users pages) and I want the convenience of the Babel like behavior that I get with webpack, but I'm not sure I am doing this the correct way. Here is what my gulpfile looks like:

elixir(mix => {
    mix.sass('app.scss')
        .styles([
            'layout.css',
            'navmenu.css',
            'respond-menu.css',
            'store.css',
        ], 'public/css/styles.css')
        .webpack('app.js')
        .webpack('components/free_looks/free-look.js')
        .webpack('components/free_looks/free-look-application.js')
        .webpack('components/notes.js')
        .webpack('components/users/users.js')
        .webpack('components/users/users-edit.js')
        .webpack('components/users/users-add.js')
        .browserSync({
            proxy: 'napa-pro-image.dev'
        });

I'm thinking there is a better way to do this and keep my JS files separate with running webpack so many times. Any ideas?

07 Aug
2 years ago

dericcain left a reply on Testing Session Variable After Authenticated

@SaeedPrez It is still not working. Just so you can see where I'm storing the session variable, here is the code in the AuthController.

public function authenticated()
 {
        Session::put('api_token', Auth::user()->api_token);
 }

Again, this is working if I manually login, so I'm not sure why the test is not working.

dericcain started a new conversation Testing Session Variable After Authenticated

When a user has successfully authenticated, I am adding a session variable to make API calls. I want to be able to test this but I am not finding a way to do so. Here is what I have tried.

/** @test */
    function a_users_api_token_is_stored_in_session_after_login()
    {
        $user = factory(User::class)->create();
        $user = User::find($user->id);

        $this->actingAs($user)
            ->visit('/')
            ->assertSessionHas('api_token');
    }

This always comes back as false. However, when I manually log in and look at my session variables, it works as expected.

Anyone know how to do this?

26 Apr
3 years ago

dericcain left a reply on Using Auth:user() In Testing Is Failing

Where are you calling actingAs? Well... must have been a long day when I posted the question. Your simple question was the solution. I could have sworn that I was using actingAs.

Thanks for the help!

dericcain left a reply on Using Auth:user() In Testing Is Failing

I am getting...

ErrorException: Trying to get property of non-object

... which is referencing the line return

$builder->where('team_id', Auth::user()->current_team_id);

21 Apr
3 years ago

dericcain started a new conversation Using Auth:user() In Testing Is Failing

I have a test that I am trying to run on a scoped DB query that returns only results from the currently logged in user's team. I am having issues with the test failing because Auth::user() doesn't seem to work when testing with actingAs. Here is my test:

/** @test */
    function a_team_has_ten_tickets()
    {
        $this->assertCount(10, $this->team_testing->tickets);
    }

And the scoped query is:

public function apply(Builder $builder, Model $model)
    {
        return $builder->where('team_id', Auth::user()->current_team_id);
    }

Any ideas why this is not working, or how to make this work?

14 Apr
3 years ago

dericcain left a reply on Testing Middleware Exception

@WM-Laravel I'm getting somewhere now. Now, I get:

1) TicketsViewTest::a_user_cant_view_other_companies_tickets
A request to [http://testing.dashdesk.dev/tickets] failed. Received status code [403].

When I run my test, which is what I want. However, I must be using the wrong assertion. I tried:

$this->actingAs(User::find(3))
            ->visit('/tickets')
            ->assertResponseStatus(403);

and...

$this->actingAs(User::find(3))
            ->visit('/tickets')
            ->see('403');

... but both of those fail. I would think that assertResponseStatus(403) would work. What am I missing?

12 Apr
3 years ago

dericcain left a reply on Using Vue To Refresh AJAX Data

On your input that is your calendar picker, add a v-on:change="fetchEventList(data)" to get the date. If I'm not mistaken, that should also update your component.

dericcain started a new conversation Testing Middleware Exception

I have a middleware that checks if a user is able to view a sub-domain. If they are not and they attempt to do so, I throw an abort(403). I cannot seem to get this to test properly. Here are a couple of things that I have tried.

Here is my middelware:

    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->guest()) {
            if ($request->ajax() || $request->wantsJson()) {
                return response('Unauthorized.', 401);
            } else {
                return redirect()->guest('login');
            }
        }

        $user = Auth::user();
        $sub_domain = array_shift((explode(".", $_SERVER['HTTP_HOST'])));
        if ($user->company->sub_domain != $sub_domain) {
            return abort(403,
                'Are you sure you meant to go here? Check the URL and try again.');
        }

        Landlord::addTenant('company_id', Auth::user()->company_id);

        return $next($request);
    }

My test...

        $this->actingAs(User::find(3))
            ->visit('/tickets')
            ->type('test@email.com', 'email')
            ->type('123', 'password')
            ->press('Login')
            ->see('403');

I tried this because I actually have the numbers 403 in an h1 tag. The error that I get is: 'ErrorException' with message 'Undefined index: HTTP_HOST' in /Users/Deric/Sites/dashdesk/app/Http/Middleware/SubdomainAuth.php:33

Any ideas why I am getting this error? Even better, any idea on a better way to test this?

06 Apr
3 years ago

dericcain left a reply on Subdomain Routing And Parameters

I've been scouring the Internet looking for this very solution. I've read tons of articles but come up empty handed so far.

02 Apr
3 years ago

dericcain left a reply on VueJS And Eloquent: Relationships

@RachidLaasri

Are you sure you included the relation in the query using with('user')*?

$questions = Question::with('user')->all();

THANk YOU!!!!

16 Mar
3 years ago

dericcain left a reply on Repository Pattern In 5.0

@ricardovigatti

In my case, i decided to create an RepositoryInterface, defining only the basic crud operations for entities (read Models). Now my PostRepository is implementing that RepositoryInterface. And my CommentRepository can implement that same interface, and other entities too.

What you think about this approach?

I think that will work fine. The only thing that you may find is that when you need to implement a method for one of your entities, but only that one entity, then your interface will force you to use that method on both of your repositories. That is the reason that I like to create one interface per repository.

However, if that solution works for you, the go for it!

One question - you said that the method I wrote about was too easy. What did you mean by that? Did you mean that the problem you are trying to solve is too complex for what I proposed? Just wondering (I actually take it as a compliment ;) )

10 Mar
3 years ago

dericcain left a reply on Repository Pattern In 5.0

I'm a little late to the game, but here is a tutorial on how to do what the OP is asking.

https://dericcain.com/blog/using-the-repository-pattern-in-laravel-5

09 Mar
3 years ago

dericcain left a reply on How To Deploy Laravel App On Vps Using Rocketeer

@d0tt Thanks for the heads up! I edited my post.

02 Jan
3 years ago

dericcain left a reply on How To Deploy Laravel App On Vps Using Rocketeer

I know this is a late response, but here is a tutorial that I wrote on this very subject.

http://dericcain.com/blog/deploying-laravel-5-with-rocketeer

Hopefully it will help someone in the future.