deanlaw

deanlaw

Member Since 2 Years Ago

Experience Points 330
Experience Level 1

4,670 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 2
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.

24 Feb
1 year ago

deanlaw left a reply on Pass Parent Value To Eager Loading Filter

@ahmeddabak

Thanks for the reply. I had actually tried using hasManyThrough, but the activities model is polymorphic and doesn't have a direct foreign key relationship with the prospect. This causes Laravel to throw an error when trying to access activities from the building model.

The other issue is that apparently neither the $this or $query variable contains a reference to the building, so I don't have access to the report_period value. I ended up splitting the functionality into two separate queries. The first grabbing the buildings and then looping over them, grabbing their prospects with activities that fall within the search criteria.

Thanks again for you help.

22 Feb
1 year ago

deanlaw started a new conversation Pass Parent Value To Eager Loading Filter

I have a relationship model as such: building->prospects->activities

I am trying to create a report that displays all building prospects and their activities if their activities fall within a certain timeframe. The problem that I have is that the timeframe is specified in the building model. This is a value which represents the number of days in the past to include within the report. This could be 30, 60, 90, 180 etc. for 1 month, 2 month, etc. in the past. So I need to create a date to filter the activities by based upon this value in the building. I can pull all buildings with their prospects and activities without a problem using the following query:

$buildings = Building::with([
        'prospects' => function ($query) {
            $query->where('inactive', '=', 0)
                ->WhereHas('activities');
        },
        'prospects.activities',
        'activityReportUsers',
        'documents'
    ])
    ->whereNotNull('report_sender_id')
    ->has('activityReportUsers')
    ->whereHas('prospects', function ($query) {
        $query->where('inactive', '=', 0)
            ->WhereHas('activities');
    })
    ->get();

But I need to be able to pass the buildings report period value to the prospect.activities. This is what I have tried, but have been unsuccessful:

$buildings = Building::with([
        'prospects' => function ($query) {
            $query->where('inactive', '=', 0)
                ->WhereHas('activities');
        },
        'prospects.activities' => function ($query) use ($this->report_period) {
            $query->where('activity_date', '>=', Carbon::now()->subDays($this->report_period));
        },
        'activityReportUsers',
        'documents'
    ])
    ->whereNotNull('report_sender_id')
    ->has('activityReportUsers')
    ->whereHas('prospects', function ($query) {
        $query->where('inactive', '=', 0)
            ->WhereHas('activities');
    })
    ->get();

I have also tried passing $query->report_period as well, which did not work as well. Any thoughts on how I can accomplish this?

18 Feb
1 year ago

deanlaw left a reply on Route::bind Has No Affect On Resource Routes

Thank you, August, that was it! I updated my bind statement in my RouteServiceProvider file to this"

Route::bind('user', function ($id) {
    $decoded_id = Hashids::decode($id)[0] ?? $id;
    return User::find($decoded_id);
});

And it worked! I was hoping that I would be able to manipulate only the id value so that I wouldn't need to set this up for each model specifically, but you can't have everything, right? Thanks again for pointing me in the right direction.

deanlaw left a reply on Route::bind Has No Affect On Resource Routes

Thanks, Dunsti. I wish that was the case. That was me just typing it wrong in the question. I updated my question. The URL that is failing, works if define the routes individually instead of using a resource route.

17 Feb
1 year ago

deanlaw started a new conversation Route::bind Has No Affect On Resource Routes

I have setup my site to utilize HashIds by using a Route:bind statement in my RouteServiceProvider file which decodes an id variable if defined in a route.

Route::bind('id', function ($id) {
    $decoded_id = Hashids::decode($id)[0] ?? $id;
    return $decoded_id;
});

This works great when I define the routes in my web routes file individually, but is ignored if I am using a resource route.

This works:

Route::prefix('users')->group(function () {
    Route::get('/', '[email protected]');
    Route::get('create', '[email protected]');
    Route::post('/', '[email protected]');
    Route::get('{id}', '[email protected]');
    Route::get('{id}/edit', '[email protected]');
    Route::put('{id}', '[email protected]');
    Route::delete('{id}', '[email protected]');
});

This does not:

Route::resource('users', 'UserController');

With the resource route, if I try to hit "/users/someHashedId/edit", I get a 404 error. But if I individually create the edit route as above, the id is correctly decoded and the edit form is displayed properly. Is there any way to specify that the app should use my bind first before trying to generate the user passed into the resource route?

  • Laravel 5.5.34
  • PHP 7.1.8
  • OSX 10.11.6