Potti

Potti

Member Since 1 Year Ago

Experience Points
190
Total
Experience

4,810 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
0
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 1
190 XP
Dec
13
1 day ago
Activity icon

Replied to Where() Returns Other Then Matched Records

it's working like a charm. thank you for explanation as well.

Dec
12
2 days ago
Activity icon

Started a new Conversation Where() Returns Other Then Matched Records

I am trying return matched or lower prices records from DB. But there something off about the code.

let's say $price = 900000 and trying to return records like below.

->whereHas("plans", function($q) use ($price){
    $q->when($price, function($query, $price){
        return $query->where("plan_price", "<=", $price);                
    });
})

it returns but,

as you see in the image here: https://imgur.com/a/sWrHpMO

it's also return more then $price I thought where() method applies iteration inside plans relation. But it doesn't check the second plan's price.

and if I use collection like below.

->when($price, function($query) use ($price){
    $query->with(["plans" => function($query) use ($price){
            return $query->where("plan_price", "<=", $price);
        }]);
})

it's working. But this time, I start to return empty plans as well... I am pretty much stuck here.

Dec
04
1 week ago
Activity icon

Replied to Handling Over 7k Records, GroupBy And Pagination

Thank you for all the answers. In the end I solved the problem by handling the pagination at server side. It's clearly right choice if you have lots of records... As he @jlrdw suggest I used Illuminate\Pagination\LengthAwarePaginator; class.

`

   $places = Place::with(["plans"])->get()->groupBy("place_name")->toArray();
                    
    $total = count($places); 
    $perPage = 11;
    
    $currentPage = LengthAwarePaginator::resolveCurrentPage();

    $currentItems = array_slice($places, $perPage * ($currentPage - 1), $perPage);
    
    $paginator = new LengthAwarePaginator($currentItems, count($places), $perPage, $currentPage);

    $results = $paginator->appends('filter', request('filter'));


    return $results;  

`

Activity icon

Started a new Conversation Handling Over 7k Records, GroupBy And Pagination

I have a situation that can't get my head around. In database I have over 7k records. So pagination at server side best thing to do. But I can't do that because I must use groupBy on the data. Official Laravel Docs says "pagination operations that use a groupBy statement cannot be executed efficiently by Laravel." and It's offering a frontend custom pagination.

What is best way to handle this kind of situation. After using groupBy should I just send all 7k to client side and apply custom pagination. Is it right way to do it? Also if I use custom pagination in frontend. Then how can I follow the page links? I mean dynamicly slicing the array and there is no url path =2 or etc... to follow the pages...

Dec
03
1 week ago
Activity icon

Replied to Using GroupBy() On Table Relations

sure, it's because I am grouping same places (it's like a duplicated rows) it doesn't matter if I loose same place_name's data. I only want it's place_id plans. and contain all plans in one place...

I tried something like below.

Place::with(["plans"])->get()->groupBy("place_name"); 

the collection above grouping places under place_name. I don't loose places as well. BUT (it's big but) then I can't use ->paginate() when I return json. I need to paginate.

So the question here. How can I group place_name and their place_id plans aswell...

Activity icon

Replied to Using GroupBy() On Table Relations

Hm, it's more clear now. But the problem that my head can't get around. "a join or a different query" part. which should I use, how should I use. If you give me an example for that. It will be really helpful. Because I am very much stuck :)

Activity icon

Started a new Conversation Using GroupBy() On Table Relations

I have a little problem about grouping belongsTo() tables...

Place Model

protected $table = "places";
protected $guarded = [];

public $with = ["plans"];

public function plans()
{
    return $this->hasMany("App\Models\Plan");
}

Plan Model

protected $guarded = [];

public function place()
{
    return $this->belongsTo("App\Models\Place");
}

In controller when I return json data I can see the relation.

$place = Place::with(["plans"])->get();

return $place;

The result is fine with this. check the image: https://imgur.com/a/0CHXPhQ

But, when I try to use groupBy() on place_name column. It doesn't group their plans in one place...

Place::with(["plans"])->groupBy("place_name")->get(); 

Results: https://imgur.com/a/qPxMU42 shows. plans doesn't grouping. It removes second place_id's plans...