vybeauregard

vybeauregard

Member Since 3 Years Ago

Alexandria, VA

Experience Points 50,180
Experience Level 11

4,820 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 497
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.

17 Jun
1 month ago

vybeauregard left a reply on Eloquent Model Events In Laravel 5.4

You're right to be confused by this, it took me a while to unpack everything I crammed in here!

Line 1, as you figured out, is an action mapped by the protected $events property on the trait class. There's actually a typo there, where the left-hand variable should be $action instead of $item. I'll edit the above code snippet to reflect this alteration.

Line 2, then, would be calling the action from above on the $item object.

04 Dec
7 months ago

vybeauregard left a reply on Laravel Calendar Add Event On Fly

You'll need to send an ajax request to persist the event on the server side. Once you've persisted it, you can return that data to dayClick and render the event.

06 Feb
2 years ago

vybeauregard left a reply on Eloquent Model Events In Laravel 5.4

Renaming my $events attribute in the trait solved my problem. Thanks, @juandmegon!

03 Feb
2 years ago

vybeauregard started a new conversation Eloquent Model Events In Laravel 5.4

In previous versions of Laravel, I was able to define an array of events and the listener action inside a trait which was then applied to several models in my app. In Laravel 5.4, I now get an error warning that the $events property was defined in Illuminate\Database\Eloquent\Model and my trait definition is incompatible. I see there's a new HasEvents trait that handles this functionality, but I haven't found any examples of it in use.

Here's a condensed version of what I had working in 5.3:

<?php

namespace App\Traits;

use Illuminate\Database\Eloquent\SoftDeletes;

trait SavesItem
{
    use SoftDeletes;

    /**
     * $events maps Eloquent events to trait methods.
     */
    protected $events = [
        'created'   =>  'createItem',
        'deleted'   =>  'deleteItem',
        'updating'  =>  'updateItem',
        'saving'    =>  'saveItem',
    ];

    /**
     * Set up event listeners for all Item types.
     * Named events are mapped to trait methods in $events.
     *
     * @return void
     */
    protected static function boot()
    {
        parent::boot();

        foreach(static::getModelEvents() as $event) {
            static::$event(function($item) use ($event){
                $item = static::$events[$event];
                $item->$action($item);
            });
        }
    }

    /**
     * Retrieve events the model needs listeners for.
     *
     * @return array
     */
    protected static function getModelEvents()
    {
        if (isset(static::$modelEvents)){
            //if a model needs fewer events available to SavesItem, define in that model's $modelEvents array.
            return static::$modelEvents;
        }
        return [
            'created', 'deleted', 'updating', 'saving'
        ];
    }

    public function createItem($item)
    {
        //runs when created event is dispatched
    }

    public function updateItem($item)
    {
        //runs when updating event is dispatched
    }

    public function saveItem($item)
    {
        //runs when saving event is dispatched
    }

    public function deleteItem($item)
    {
        //runs when deleted event is dispatched
    }

}

Any pointers on how to proceed?