beerbuddha

beerbuddha

Member Since 5 Years Ago

Experience Points 28,340
Experience Level 6

1,660 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 317
Lessons
Completed
Best Reply Awards 1
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.

08 Jan
2 months ago

beerbuddha left a reply on Low Request Per Second With Laravel, Docker, And AWS

@KREITJE - thanks for your input - I checked with the IT department and we use HVM

17 Dec
3 months ago

beerbuddha left a reply on Low Request Per Second With Laravel, Docker, And AWS

@OHFFS - thanks for the blackfire suggestion - now i need to figure out how to install it within docker as an agent.

beerbuddha left a reply on Low Request Per Second With Laravel, Docker, And AWS

@OHFFS - readjusted to the opcache you have suggested still tapping out at 300 users hatching at 10 users/sec with a 20 req/s

ugh.

beerbuddha left a reply on Low Request Per Second With Laravel, Docker, And AWS

@OHFFS - I think we were responding at the same time. See my response above as I figured out the zend opache and it was enabled.

beerbuddha left a reply on Low Request Per Second With Laravel, Docker, And AWS

@OHFFS - Ok so I wasn't able to disable the loging yet however

  • enabled route:cache
  • enabled config:cache

slight improvement (gain a few more users concurrent but I am not getting what you are achieving.

Now opcache - im still trying to figure it out. I tried the opcache one from laravel-news from Paul Redmond but he uses the php-7.2fpm docker container where as i am using the ubuntu one.

i tried using his basic (static) configuration for the opcache.ini and restarted nginx + php-fpm - nothing

as far as the docker is concern it had a opcache.ini and opecache.so zend_extension but that is all i can descern - i couldnt tell if it was active but when i re-ran the load-test i didnt see any improvement.

16 Dec
3 months ago

beerbuddha left a reply on Low Request Per Second With Laravel, Docker, And AWS

@MARKOTITEL - I have to use AWS accounts. moving it to another account is not an option

15 Dec
3 months ago

beerbuddha left a reply on Low Request Per Second With Laravel, Docker, And AWS

@OHFFS - AWS == (im not triple = it) DO == Linode == any given cloud computing. They are a beast but you are also trap with certain things with them. An EC2 machine is about the same thing that a forge machine would spawn up. So you dont need to be a AWS user - its basically an ubuntu cloud machine just like the rest of them. Just that AWS has better overall eco-system in terms of cost for the volume. shrug not my call.

Doing the docker swarm won't help trying to solve the bottle neck because I dont want to spawn more instances to see how well the load will be. That defeats the purpose of horizontal scaling. Basically its just like putting a load-balancer on top (which i remove to do the test) and having several instances on the bottom. The fundamental difference is that instead of you making the decision you ask the swarm to deal with it as the EC2 instances would be group together.

Now about the logging - yes i do some logging However as i mentioned - If i take out the entire controller idea and just go: "what if i just read 2 queries and write two queries inside a closure routes/api.php file what is my throughput. it fairs better but not best. at 600 users with a 134 req/s. Still no where near where it should

beerbuddha left a reply on Low Request Per Second With Laravel, Docker, And AWS

@OHFFS - glad to hear that i am not crazy to think that the app is under performing. I cannot move it away from docker because our infra is built around it and we will eventually move into docker swarm kubernetes system. This is only but one cog. if your follow up question would be: are there any other dockers running on this machine - i would say no not at this moment because we wanted to isolate it in order to run the load test.

beerbuddha left a reply on Low Request Per Second With Laravel, Docker, And AWS

@MARKOTITEL - I do not own the instance - so i can't tap into the AWS account itself. as far as they are reporting there are nothing choking on that front. I am directly taping into the instance - no load balancer.

  • composer install --no-dev --no-interaction --optimize-autoloader"

already done

beerbuddha left a reply on Low Request Per Second With Laravel, Docker, And AWS

@MARKOTITEL - I mentioned it already

  • it taps out all 8 cores. less than 1gb used out of the 16GB.
  • the error message itself is that the php-fpm cannot get service.

IF you still want to see it from htop It will be included in the main post

beerbuddha left a reply on Low Request Per Second With Laravel, Docker, And AWS

@MARKOTITEL - the rds doesn't get tickled. its on low usage and the queries themselves are in the single digits ms. (or 0 << zone). as far as smaller instance goes yes i have. The project used to be on a 2 core 4gb EC2 machine. it choked out at approx less than 80 users at approx 10 request/s

beerbuddha left a reply on Low Request Per Second With Laravel, Docker, And AWS

@OHFFS - hey thanks for the response

  • as i mention all the api is doing is authenticating the user using passport and then writing to redis. I enabled profiling and has determine that pastport / oauth2 does 4 queries - 2 reads and 2 writes. I added the extra redis write due to business objective.
  • the DB is a mysql 5.7 running on a rds instance (so not in the box)
  • I am trying to scale but i am also trying to see (just like a gamer) did i squeeze out all i had on this machine. As you can see (and concluded) this machine SHOULD handle way more

beerbuddha started a new conversation Low Request Per Second With Laravel, Docker, And AWS

  • Laravel 5.5
  • Php 7.0
  • AWS 8 cpu / 16GB
  • Docker with nginx/php inside.

I have an api that serves oauth2.0 via passport. It was working fine for low volume traffic but since we have ramped up traffic it buckled. We have a docker application on an EC2 machine with 8 cpu / 16gb ram / SSD. All it the api serves is email/password/client_id/client_secret check, then write the token into the DB, and the user data inside a redis store. (2 read / 2 writes / 1 write to redis). It returns a JWT access_token and a refresh_token (plus the ttl)

The laravel application is dockerized via an ubuntu docker + nginx + 7.0php-fpm with the necessary extensions. (its the same dockerize that Chris Fidao created in his series shippingwithdocker)

I ran locust.io server (on another ec2 machine on AWS) testing at 200 users / 10 hatch/sec and 100% cpu utilization on all cores. If i increase it to 255ish - I start having some 502 bad gateways. I check the php log and php-fpm is unable to service anymore calls. I made a tweak to the php-fpm.conf file: pm = ondemand with 200 children, 1000 max request. I am able to achieve 300 more users at 15 hatch/sec 100% cpu utilization. As another test - what i have done is taken the RAW read DB query + raw insert query and removed redis writting - simply wrote it as part of the routes/api.php closure and let it ripped. I managed to get up to 500 users approx with 134 request/second (no controllers)

My question is: does these metrics seems wrong to anyone? I have an 8 core / 16GB and im getting a low throughput? after finding Taylor Otwell's blog about how he manage to hit 500+ request/sec with a 2GB ram machine on Digital Ocean - is there a setting that I should be checking? I am just trying to ensure that this is my final benchmark metrics and effectively in order to receive more request - I should add another server under a load balancer.

13 Dec
3 months ago

beerbuddha left a reply on Nova BelongsToMany Breaks Memory Cap

@AURAWINDSURFING - Its not a controller - its with NOVA If i built it myself with a controller i wouldn't load 30k records within a relationship in one shot.

as far as the exact error:

"Allowed memory size of 134217728 bytes exhausted (tried to allocate 14680072 bytes)","code":1,"file":"/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:330"
10 Dec
3 months ago

beerbuddha left a reply on Nova BelongsToMany Breaks Memory Cap

@AURAWINDSURFING - Yet its a php out of memory error message that i received - so how can it be a javascript error?

beerbuddha left a reply on Nova BelongsToMany Breaks Memory Cap

@AURAWINDSURFING - yeah im trying to increase the memory because users will keep coming in.

to replicate the situation its pretty easy. have a belongstomany relationship with any given class and load up 30k attach to the relationship (think 1 thread belongstomany users) then factory 30k users to it

the resource won't load.

No i need to show the resource with the relationship or else it defeats the purpose. The problem there are currently (as far as i can tell) a way to only load the limited amount with pagination despite visually it limits it and uses pagination

09 Dec
3 months ago

beerbuddha left a reply on Nova BelongsToMany Breaks Memory Cap

@AURAWINDSURFING - I think you are miss-reading the problem.

The index is not an issue here unless and only if, i try to eager load the relationship. the problem is in the detail resource. Within a given detail resource if it has a belongstomany relationship resource it will tap out on the memory, however during display it only shows 5.

No i am not actually interested in seeing all the 30k relations but Nova automatically loads all of them despite only showing 5 at a time with pagination - that is the real issue here.

06 Dec
3 months ago

beerbuddha started a new conversation Nova BelongsToMany Breaks Memory Cap

In Nova 1.2.0 / Laravel 5.7.14

I have a BelongsToMany that is breaking the php memory when it is being pulled. I have a resource that I can see the count of (over 30000) from a BelongsToMany - when I click to the detail of the resource - it tells me that it hit a memory cap.

According to the doc i can only find: https://nova.laravel.com/docs/1.0/resources/relationships.html#morphtomany

Searchable relation

HOWEVER - this solution is only for Create/Update - I need one for the Detail. When it finish rendering - I will get pagination but the page won't load at all. Any idea for solution?

I tried using telescope but to no avail to solve this.

As an example I have a Thread class on index I can see how many users and on Detail I hook myself with a belongstomany

            Number::make('Users', function () {
                return $this->userCount();
            })
                ->hideWhenCreating()
                ->hideWhenUpdating(),   
            BelongsToMany::make('Users', 'users', Users::class)->fields(function () {
                return [
                    Text::make('weight', 'value'),
                ];
            }),

It just break the detail page

20 Nov
3 months ago

beerbuddha left a reply on Nova Panel Width Resizing

@EJDELMONICO - good approach - will check - thanks

beerbuddha left a reply on Nova Panel Width Resizing

@EJDELMONICO - yeah i tried - but i need a blueprint to base myself on. the nova-components so far as example:

  • entirely new resource dashboard
  • custom cards.

need something on the panel level. so far its everything but the panel

beerbuddha left a reply on Nova Panel Width Resizing

@EJDELMONICO - hi, i didnt want the resizing of the cards ...i asked for panels. the width function is for cards and im asking for a way to resize panels.

17 Nov
4 months ago

beerbuddha left a reply on Nova Actionable - How To Extend Or Show Field

@LARS-JANSSEN - but how does it attach to nova?

beerbuddha started a new conversation Nova Panel Width Resizing

With cards ->width('1/3'); can be used to take 1/3 of the space.

How would one do with a panel (i tried it said the function doesn't exist) as i have a model with many attributes and some relationships So instead of scrolling I wanted to group 2 pannels together but have them on split view horizontally (as if it was a card)

beerbuddha left a reply on Nova Actionable - How To Extend Or Show Field

@LARS-JANSSEN - Good old Spatie to the rescue. Thanks!

15 Nov
4 months ago

beerbuddha started a new conversation Nova Actionable - How To Extend Or Show Field

The idea of actionable is interesting with Nova - however I thought it would have been a history record log. So far it shows me "who did what and to what element" however its missing the "value" portion. As i dig into the trait - its a morphTo ... thats when i got lost.

Has anyone achieve customization for the Actionable trait to display extra columns...or to display more columns / relations in that section of the table?

So for example If a user Edited - i would like to know what they edited and possibility (within range) what was the previous value.

05 Nov
4 months ago

beerbuddha started a new conversation Nova BelongsTo Relationship Resource Creation Yields 404

Hi

I have the latest released 1.1.7.

I have two resources - once of which is a relationship When I create a relationship entry coming from the parent (so think user -> post and I am creating a post which has belongsto relationship as per documentation example)

I get that the relationship has been created (green message) BUT I then get a 404. As i do an inspect, the resource ID is not passed (its shown as undefined) from the nova-api//undefined

as I check the response it says: No query results for model

effectively that makes sense because no ID is being passed. I dont know what is going on or how to debug the fact that the ID from the parent relationship is missing yet the relationship has been created.

as far as my "fields" for my relationship model goes:

             ID::make('post_id', 'post_id')
                ->sortable()
                ->resolveUsing(function ($post_id) {
                    return (string)$post_id;
                }),
            Select::make('rating')
                ->options($value)
                ->sortable(),
            BelongsTo::make('User', 'user', User::class)
                ->hideWhenCreating()
                ->hideWhenUpdating()
                ->withMeta(['belongsToId'=> (string)$this->post_id])
                ->rules('required'),
        ];

Note I use the resolveUsing because the post_id are bigint and due to JS limitation with bigint - i have to convert them into strings for it to work.

19 Oct
5 months ago

beerbuddha left a reply on How To Bulk Edit In Nova

@bryanmonzon thanks for pointing that out - appreciated

beerbuddha left a reply on How To Bulk Edit In Nova

@bryanmonzon code wise is ...?

18 Oct
5 months ago

beerbuddha left a reply on How To Bulk Edit In Nova

Sure. Lets take Nick Basile's Deep dive into Nova: https://nick-basile.com/blog/post/deep-diving-laravel-nova

in the lead resource - if i want to select several leads (or all) i can - but then I would like to take an action on it (ie change PROSPECT to LEAD) - how would one do it? - hence the bulk edit question

16 Oct
5 months ago

beerbuddha started a new conversation How To Bulk Edit In Nova

I know you can set a boolean (or fixed field) as an action (such as deactivating)

How would one bulk edit - like I have a resource of Items and I would like to change the prices on select items to be a certain amount.

So far I have managed to adventure to the Action part - however I am uncertain how to invoke it properly.

10 Oct
5 months ago

beerbuddha started a new conversation How To Effectively Microservices With Nova

Hi

I have several microservices that I am fetching data from (the bane of microservices) - so i do not control all the DB entries points - is there any one who has successfully leverage microservices and the nova together? I would like to know some form of high level workflow if possible, (examples of user->post->comments) is fine.

Normally (in regular laravel application i have built) I would create a service - that feeds itself Guzzle and get set via config which service url it needs

then I would call such service inside a controller / manager to fetch the required data - then once the data is return - operate logic. When I would work with a Front-end developer on this with Laravel as the "service" I would make sure the controller is json formatted so that the vue-components for the front end receive the data. I haven't been able to figureout if Nova can easily solve this (or be extendible) in regards using Nova as the boilerplate front-end and then the back-end laravel application are calling the microservices instead of having eloquent do it.

Or perhaps Nova can't be coupled or not yet flexible for such feature. tks for the help

17 May
10 months ago

beerbuddha started a new conversation Queue::bulk Not Testable

I was able to use Queue::bulk to send a bunch of queue jobs and have Queue::fake test them.

For some reason this week (May 11ish) - this is no longer the case and without changing my tests i have to use Queue::pushOn() instead.

version of laravel: "version": "v5.5.21",

15 May
10 months ago

beerbuddha started a new conversation Why Goto Was Used Inside The Laravel Framework

So on twitter this little discovery escaped me, a goto command inside a laravel helper: https://github.com/laravel/framework/blob/35a8805603b63e18949cab5bb1c260261ddc1435/src/Illuminate/Support/helpers.php#L780

now obviously - inside php manual there is a xbdc meme about it: https://stackoverflow.com/questions/1900017/is-goto-in-php-evil

I was just wondering - do/while...or while infinite break....but goto?

do it just boil down to readability?

11 Apr
11 months ago

beerbuddha started a new conversation Better Way To Submit Json Data In Post Test

I currently have this testable piece of code to submit a json filled data via post. I let my controller do its thing and respond back.

$responseKey = 'abcdabcd6b1649f681a408f1beebabcd';
        $sendJson    = $this->createSaleResponse($responseKey);
        $sendHeaders = [ 'CONTENT_TYPE' => 'application/json' ];
        $response = $this->call(
            'POST',
            'ext-purchase-api/api/roku/notifications',
            [],
            [],
            [],
            $sendHeaders,
            $sendJson
        );
        $this->assertEquals(200, $response->status());
        $receiveData = $response->getContent();
        $this->assertEquals($responseKey, $receiveData);
        $response->assertHeader('ApiKey', $secret);

I am used to the restful API of $this->get and $this->post - is there a better way to format this code?

23 Feb
1 year ago

beerbuddha left a reply on Any Reasonable Reason To Use Yield?

@Cronix the example from the php page did not enlighten on the reasoning behind using yield.

beerbuddha started a new conversation Any Reasonable Reason To Use Yield?

I never knew the function yield existed in PHP until Laravel's Illuminate/Database/Connection.php

line 369 (from Laravel 5.5) - has

        while ($record = $statement->fetch()) {
            yield $record;
        }

im so used to foreach/while standard that i dont get why a yield is useful here.

Anyone able to explain?

14 Feb
1 year ago
13 Feb
1 year ago

beerbuddha started a new conversation Laravel Passport Not Respecting Oauth Refresh_token?

Hi I have a laravel application (5.5) using passport but the refresh_token seems weird.

I thought refresh_tokens can be kept (hence why long lived) to request new access_tokens until revoked/expire

but within laravel passport - it is a one time usage.

I was in the assumption from the following articles:

https://auth0.com/blog/refresh-tokens-what-are-they-and-when-to-use-them/ https://medium.com/@bantic/more-oauth-2-0-surprises-the-refresh-token-1831d71f4af6

that indeed refresh_tokens doesn't refresh the access_token but grant you new ones but while granting new ones - it grant me a new refresh_token to use and actually revoked the old one.

  1. is this weird behavior? or is this how it is suppose to be??
  2. is there a way to make the refresh_token be reusable to grant access_tokens until revoke/expire
14 Jan
1 year ago

beerbuddha started a new conversation Using FormRequest To Power Routes

For those who are Taylor Otwell's Laravel tip, has anyone been able to figure out where he has gotten the return query from?

use App\Order;
use App\Http\Requests\OrderSearchRequest;

Route::get('/', function (OrderSearchRequest $request) {
    $request->filters()->each->apply(Order::newQuery());

    return $query->get();
});

was the final refactor but variable $query was never declared so I am wondering where it came from. Can anyone help?

12 Dec
1 year ago

beerbuddha started a new conversation One Time Usage For Laravel Passport Refresh_token ?

So i am using passport to implement OAuth2.0 - however I've been told (and also assumed) that the refresh_token is long lived. (which is the case) but also multiple usage.

After experimenting with Laravel Passport - I found that it maybe long lived - but its a single usage - when you invoke the refresh_token grant - you get a new refresh_token with the new access_token.

As per documentation: refresh_token is to obtain a new access_token - not to refresh the access_token. I wanted to know if the one time usage is from Laravel Passport point of view or has it always been like this?

I cannot find documentations about how many usage the refresh_token is suppose to be.

19 Oct
1 year ago

beerbuddha started a new conversation Using Caching A Bit More OOP

I have the following for index() inside my controller:

 $members = Cache::remember('members'.sha1($membershipsBuild->toSql()), env('CACHE_MEMBERS_TIME', 0.001), function () use ($membersBuild) {
                return $membersBuild->get();
            });

My questions are:

  1. is there a better OOP approach? Ie can I avoid the helper? I am aware that it is actually a contract but If i send the contract - I will need to fetch the instance afterward.
  2. is there a better approach to past the TTL of the cache instead of ENV? feeding it an arbitrary fixed number seems wrong..but this is my best way for this for now.
  3. when adding cache - so far with this solution - makes tests past - Is there any usefulness in testing the cache itself? I mean I could in theory mock it but that would be a separate test on itself...However i find it tidious to do it. Any opinions on that?
18 Oct
1 year ago

beerbuddha left a reply on How To Implement Middleware Structure Design

Well in terms of application (let it be SasS or PasS) Business Logic is define as: your features.

It the most raw term: "whatever you do to the content-data in terms of manipulation"

example:

  • Give me a list of customers's data (first name, last name, DOB) - content-data - can be fetch via a lean microservice (in laravel it can be model->find();)

business logic on top of it:

  • give me all patients thats has been Sick for the past 4 weeks and their symptoms. (which in term we can present it inside a dash board).

that means->go fetch user data->then load relationships->remove non-essential items (so using fractal...i can remove pivot data if necessary) and then return. I would typically make a controller "/sickpatients/" which returns only patients that was sick, this way the given client (so lets say blade or vue) can just fetch everything and present it to the client.

beerbuddha started a new conversation How To Implement Middleware Structure Design

So Laravel has it's own middleware which you can use for validations for example.

My coworker insist that "business logic" be put in the middleware and the API logic becomes the microservice then VUE/blade can be the front-end presentation.

However - with the ease of Laravel - I've put some logic inside controllers.

Is the same middleware that my coworker is talking about the same middleware found in Laravel?

If not - then where / how would you structure the separation of: Presentation -> middleware -> microservice?

13 Oct
1 year ago

beerbuddha started a new conversation What Is The Proper Approach To Service Batch Request Via API

I am using Laravel 5.5 as a CMS.

My coworker is the frontend - I am the backend.

I treat frontend as a client (so if it was mobile or other application written in angular) as a contract work where I service API as a backend developer.

My issue currently (despite working so far) is that clients (let it be the frontend developer or a project owner) wants faster speed. Then they utter the words

"can't we send everything in a batch bundle and you as a back end treat it as such"

Now as much as i like developing restful api - I honker down to: "ok well...send your POST/PUT as a json - and I will treat it as a field and unroll it"

On gut feeling - I loose a lot of the simple fundamental on restAPI validation (ie ifi use the validator I have to first check if json is correct, then i let it go through and i need to build another layout for individual mini post data.

Does anyone have a good solution to avoid a single entry point of a controller that does a large singular unrolling?

Now as an example:

  • given a form written in vue.js - you can allow the user to chain up forms for submission. (similar to where you can hit the + symbol and a new mini form opens up and you can chain up to N forms). Ideally I would like for each part of the form to be submitted to each restful endpoint - however practically (for speed) vue.js will bundle everything into one submit.
12 Oct
1 year ago

beerbuddha started a new conversation Dusk With Vue.js Testing

Seeing this piece of news: https://laravel-news.com/vue-js-unit-testing-utils

Has anyone successfully integrated this into Laravel Dusk? Or is Laravle Dusk not appropriate for this

10 Oct
1 year ago

beerbuddha left a reply on Eager Loading OrderBy Not Working As Expected

Thanks to @Snapey - I rolled back and with the help of the following person (3 years ago) https://laravel.io/forum/02-10-2014-several-eager-loading-with-constraints

I have found that I need to nest it:

$data = $this->users
    ->with([
        'roles' => function ($q) {
            $q->with(['tabs' => function ($q) {
                $q->with(['department' => function ($q) {
                    $q->with(['panel' => function ($q) {
                        $q->orderBy('position', 'asc');
                    }])->orderBy('position', 'asc');
                }])->orderBy('position', 'asc');
            }])->orderBy('position', 'asc');
        }
    ])
->findOrFail($id);

beerbuddha left a reply on Eager Loading OrderBy Not Working As Expected

@Snapey you are correct - with only 1 eager loading - it is working as respected - it is when you start chaining them - that the first relationship doesn't respect it anymore.

the position column is almost everywhere (its similar if I wanted to order them with created_at which is everywhere also

beerbuddha left a reply on Eager Loading OrderBy Not Working As Expected

@Snapey one issue with giving a new relation is that now I have to use the new relation name instead of the old one.

I have to modify all old reference of $user->roles-> to $user->rolesAsc instead.