faroutchris

faroutchris

Member Since 3 Years Ago

Stockholm

Experience Points
17,260
Total
Experience

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-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.

Level 4
17,260 XP
Jan
03
9 months ago
Activity icon

Replied to 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 :)

Activity icon

Replied to Combine GroupBy And WithCount Query

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

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!

Activity icon

Replied to 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.

Activity icon

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 leagues grouped by category.

I would like to write a method that returns an extra field in the array of leagues to show how many related events exist for each league.

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);
    }
}

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.

Nov
04
11 months ago
Activity icon

Replied to Help Needed With Caching Data From API Request

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

The Event and the Stats are different models in my application.

Activity icon

Replied to 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($field); 
                // is there some kind of mass assignment, like I can do with php artisan db:seed 
    
            }
        }

     })-> everyTenMinutes();
}

I'm not sure that I want to always hit their API. With a naive approach I would hit all of the 34 different API endpoints I use to get fresh data.

Could/should I check each table and see if the data is older than 10 minutes in the schedule function and run the queries as needed? But then some data that doesn't fit the criteria of being older than 10 minutes might not get updated.

Activity icon

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 :)

Nov
07
2 years ago
Activity icon

Replied to 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 adding the URL to the command

vagrant box add laravel/homestead https://atlas.hashicorp.com/laravel/boxes/homestead

If that fails, download the box manually: Enter this address to start the download: 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