faroutchris

faroutchris

Member Since 3 Years Ago

Stockholm

Experience Points 17,260
Experience Level 4

2,740 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 171
Lessons
Completed
Best Reply Awards 0
Best Reply
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.

03 Jan
5 months ago

faroutchris left a reply on Combine GroupBy And WithCount Query

@STAUDENMEIR - Thanks stuadenmeir! After renaming my model and fixing the other issues, this call correctly built the object I wanted :)

faroutchris left a reply on Combine GroupBy And WithCount Query

I figured it out, I am passing in the Event class directly in my $this->hasMany() call. It should be a string.

It still doesn't work since it seems that Event is kind of a reserved word in Laravel so I need to rename the model and see if that makes a difference.

Thanks for helping out!

faroutchris left a reply on Combine GroupBy And WithCount Query

Hmm. I tried this before and I get Use of undefined constant Event - assumed 'Event'

Seems I have some other issue in my code then. I can use the Event model directly but it seems it can't be found by Eloquent.

faroutchris started a new conversation Combine GroupBy And WithCount Query

I have two tables that are related in my database, leagues and events. One of my endpoints offers a list of all leaguesgrouped by category.

Here's the relevant parts of my models:

class League extends Model
{
    public function events()
    {
        return $this->hasMany(Event);
    }

    public function getByGroup() 
    {
        return $this->all()->groupBy('group');
    }
}
class Event extends Model
{
    public function league()
    {
        return $this->belongsTo(League);
    }
}

I would like my getByGroup method to return an extra field in the array to show how many related events exist for each league.

Here's an example output of what I would like to have:

{
...
  "Basketball": [{
     "id": 4,
     "active": true,
     "group": "Basketball",
     "details": "US Basketball",
     "title": "NBA",
     "events_count": 5 <--- this is what I want
   }],
   "Football": [{...}, {...}, {...}]
...
}

Currently I am solving this by calling an additional function in my controller that adds up each event. This results in an extreme amount of calls

I can't seem to figure out how to get this to work. I've tried following some advice on StackOverflow for similar questions and looked at the Laravel documentation but I only seem to either not get my expected output or crash the app.

04 Nov
7 months ago

faroutchris left a reply on Help Needed With Caching Data From API Request

{
    "key":"soccer",
    "label":"Soccer",
    "teams":[
        "Liverpool",
        "Red Star Belgrade"
    ],
    "event_start":1541526900,
    "stats": [
        "score": [0, 1],
        "corners": [1, 2],
        "substitutes": [
            [{"Naby Keïta", "James Milner"}], []
        ]
        // etc
    ]
}

So, in this case I would need to update the stats as they come in and maintain a one-to-many relationship between my Event Model and my Stats Model.

faroutchris left a reply on Help Needed With Caching Data From API Request

Yeah, I looked into the schedule, but am I to understand that this is roughly the correct approach:

// psuedocode
...
protected function schedule(Schedule $schedule)
{
        $schedule->call(function () {

        $client = new \GuzzleHttp\Client();
        $res = $client->request('GET', 'https://api.com/someresource');

        if ($res->getStatusCode() == '200') {
            
            $body = $res->getBody();
            
            foreach($body['data'] as $field) {

                DB::table('resource')->delete();
                DB::table('resource')->add($res); 
                // is there some kind of mass assignment, like I can do with php artisan db:seed 
    
            }
        }


                
        })-> everyTenMinutes();
}

faroutchris started a new conversation Help Needed With Caching Data From API Request

Background: I have a website/service that I'm building where the bulk of my data comes from an external API. This API has a limit of 150 000 requests per day. The data is basically live data and I want to throttle the amount of times I hit their endpoints (basically cache it).

So my plan is to run queries against this API almost like on a schedule and store the responses in my database. If an entry in my table is older than 10 minutes I want to make a request to the API and get fresh data.

By querying the data every 10 minutes, in a worst case scenario, I can get down to ~50 000 requests per day.

I'm not sure what the right approach is. I'm mainly a frontend/React developer so my experience designing backends with caching and scale in mind is limited.

Has anyone done something similar, if so, how did you approach this? I'd like to get some kind of high level overview of how to design such a system.

I can probably set up a Resource class that gets the data but as I've looked in the documentation, the Resource is usually consumed directly by the views. Can I use my Resource to update the underlying DB with the data?

I've also thought about using something like Redis instead of the DB (but then I can't really decorate the data and set up relationships which has been really nice).

I hope my question is clear enough :)

07 Nov
2 years ago

faroutchris left a reply on Issue During The Laravel Homestead Installation

Looks like you have the correct command and it's pointing to the correct address on atlas.hashicorp.com's server.

Try vagrant box add laravel/homestead https://atlas.hashicorp.com/laravel/boxes/homestead If that fails, download the box manually: Enter this address: https://atlas.hashicorp.com/laravel/boxes/homestead/versions/0.5.0/providers/virtualbox.box When it's finished you can run vagrant box add laravel/homestead path/to/your/local/file