MikeMacDowell

MikeMacDowell

Head of Business Systems at Anthony Best Dynamics Ltd

Member Since 4 Years Ago

Bristol

Experience Points
119,730
Total
Experience

270 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
1026
Lessons
Completed
Best Reply Awards
27
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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 24
119,730 XP
Apr
30
1 month ago
Activity icon

Commented on Find The Nouns

@jeffreyway this is going to be my go-to video for explaining this database design pattern, so thank you!

Far too many times I see people who would reach for a Many-to-Many relationship between Products and Retailers and store all the information about the Stock on a pivot table, because they see "product_id" and "retailer_id".

What the really care about in is Stock, and so should be treating Stock as a first class citizen and giving it its own model (and therefor all the available conveniences with it being a model).

Feb
17
3 months ago
Activity icon

Awarded Best Reply on Hijack Password Reset

If you want to replicate what you've done here, I'd suggest overriding the sendResetResponse method in PasswordController

    /**
     * Get the response for a successful password reset.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  string  $response
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
     */
    protected function sendResetResponse(Request $request, $response)
    {
    $user = $this->guard()->user();

    session(['api_token' => $user->api_token]);
        session(['season' => Season::where('active', 1)->first()]);
        session(['centres' => Centre::where('active', 1)->get()]);
        session(['centre' => Centre::findOrFail(auth()->user()->centre_id)]);
        session(['user' => $user]);

        return redirect()->route('home') ;
    }

Or just override the resetPassword method so the user isn't logged in and is required to then authenticate and your method gets hit then?

Feb
15
3 months ago
Activity icon

Awarded Best Reply on Every Page Load Calls A Method That Is Supposed To Only Run Once

Okay, I understand more about what you're asking now - you can't use Javascript to protect the endpoint being hit more than once total - because if 100 people have the same page open, it's going to countdown to zero on each of their pages and you'll get 100 requests sent to the server. This will cause your job to get dispatched multiple times, even if you're checking for a completion status (as this is a race hazard https://en.wikipedia.org/wiki/Race_condition)

You'd be better to have the time countdown on your server and the Event be executed at the point your server wants. This does mean that the timer on your front-end is independent of the server time, but you can run a request on an infrequent basis to re-sync it to the server

Feb
14
3 months ago
Activity icon

Replied to Every Page Load Calls A Method That Is Supposed To Only Run Once

Okay, I understand more about what you're asking now - you can't use Javascript to protect the endpoint being hit more than once total - because if 100 people have the same page open, it's going to countdown to zero on each of their pages and you'll get 100 requests sent to the server. This will cause your job to get dispatched multiple times, even if you're checking for a completion status (as this is a race hazard https://en.wikipedia.org/wiki/Race_condition)

You'd be better to have the time countdown on your server and the Event be executed at the point your server wants. This does mean that the timer on your front-end is independent of the server time, but you can run a request on an infrequent basis to re-sync it to the server

Activity icon

Replied to Hijack Password Reset

If you want to replicate what you've done here, I'd suggest overriding the sendResetResponse method in PasswordController

    /**
     * Get the response for a successful password reset.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  string  $response
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
     */
    protected function sendResetResponse(Request $request, $response)
    {
    $user = $this->guard()->user();

    session(['api_token' => $user->api_token]);
        session(['season' => Season::where('active', 1)->first()]);
        session(['centres' => Centre::where('active', 1)->get()]);
        session(['centre' => Centre::findOrFail(auth()->user()->centre_id)]);
        session(['user' => $user]);

        return redirect()->route('home') ;
    }

Or just override the resetPassword method so the user isn't logged in and is required to then authenticate and your method gets hit then?

Activity icon

Replied to Every Page Load Calls A Method That Is Supposed To Only Run Once

There's nothing wrong with your Vue component (I copied and compiled it up myself), so are you sure that the endpoint is being hit by this component?

Maybe add a query string to the uri and check for it in the controller as a debug tool?

Is this controller method being called anywhere else in your code?

Activity icon

Awarded Best Reply on How Can I Load A Relationship On Illuminate\Support\Collection

Load the relationships before the pluck. All of the collection methods return the Illuminate\Support\Collection class because they are defined on that class.

This should work:

$this->groups->load('thread.tags')->pluck('thread.*.tags.*.name');
Activity icon

Replied to How Can I Load A Relationship On Illuminate\Support\Collection

Load the relationships before the pluck. All of the collection methods return the Illuminate\Support\Collection class because they are defined on that class.

This should work:

$this->groups->load('thread.tags')->pluck('thread.*.tags.*.name');
Jan
15
4 months ago
Activity icon

Replied to Laravel Joining Issue With Two Tables

This is Eloquent 101 - you can watch a series on Relationships here https://laracasts.com/series/eloquent-relationships

To do it in this case you'd do:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class branchname extends Model
{

    public function course()
    {
        return $this->belongsTo(coursename::class, 'course_id');
    }

}
Activity icon

Replied to Laravel Orderby Uses

Not from the database, but if you have a collection of users you can use the collection method sortBy

$sorted = $collection->sortBy(function ($user, $key) {
    return $user->fullName();
});
Activity icon

Replied to Replicate Magento's Layered Navigation

If you don't know how many attributes you're going to be giving on any given request, the only way I can think of is this:

web.php

Route::get('category-name/{parameters?}', '[email protected]')->where('parameters', '.*');

Controller

    public function test(Request $request, $parameters)
    {
        return explode('/', $parameters);
    }

This gives you the parameters in an array which you could then use for filtering. It's messy because you'd need to put a name and a value in each parameter unless you want to only filter one attribute if another has already been filtered by.

Activity icon

Commented on Database Notifications

@JeffreyWay using ->markAsRead() on the DatabaseNotificationCollection still causes the N+1 issue as it's a collection method that just runs a database query for each Notification. Unless there's something I'm missing?

It would probably be better to write a mass update query?