mansoorkhan8

Member Since 8 Months Ago

Experience Points
2,710
Total
Experience

2,290 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
22
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

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

  • Community Pillar

    Earned once your experience points ranks in the top 10 of all Laracasts users.

Level 1
2,710 XP
Feb
25
1 week ago
Activity icon

Replied to Media Manager

I know this question is 1 year old but I would like to add my answer to help other people.

You can use this amazing package, It has a lot of features to offer.

https://github.com/ctf0/Laravel-Media-Manager

They also have a demo to check if you get errors.

https://github.com/ctf0/demos/tree/media-manager

Feb
23
1 week ago
Activity icon

Awarded Best Reply on Eloquent Condition Inside Nested With()

I use this amazing package, https://github.com/topclaudy/compoships And this is the solution I have come up with.

// App\Models\Level
public function studentsExaminationResult()
{
    return $this->hasMany(Student::class, 'level_id');
}

// App\Models\Student;
use \Awobaz\Compoships\Compoships; // Package Trait to be able to use multi foreign key relations
public function examination()
{
    return $this->hasMany(
        Examination::class,
        ['student_id', 'level_id'],
        ['id', 'level_id']
    )
    ->orderBy('subject_id');
}

// App\Http\Controllers\ExaminationController;
$examinationResult = Level::with([
    'subjects',
    'studentsExaminationResult' => fn ($query) => $query->with([
    'examination' => fn ($inner_query) => $inner_query->where('year', $year)
           ->where('term', $term),
    ]),
])->get();
Activity icon

Replied to Eloquent Condition Inside Nested With()

I use this amazing package, https://github.com/topclaudy/compoships And this is the solution I have come up with.

// App\Models\Level
public function studentsExaminationResult()
{
    return $this->hasMany(Student::class, 'level_id');
}

// App\Models\Student;
use \Awobaz\Compoships\Compoships; // Package Trait to be able to use multi foreign key relations
public function examination()
{
    return $this->hasMany(
        Examination::class,
        ['student_id', 'level_id'],
        ['id', 'level_id']
    )
    ->orderBy('subject_id');
}

// App\Http\Controllers\ExaminationController;
$examinationResult = Level::with([
    'subjects',
    'studentsExaminationResult' => fn ($query) => $query->with([
    'examination' => fn ($inner_query) => $inner_query->where('year', $year)
           ->where('term', $term),
    ]),
])->get();
Feb
22
1 week ago
Activity icon

Replied to Eloquent Condition Inside Nested With()

I have checked this last night. It works for me.

Feb
21
1 week ago
Activity icon

Started a new Conversation Eloquent Condition Inside Nested With()

Hi, I need some help! On line number 3, I want to pass student.level_id (dynamic value from within the query results) in where('level_id', ??) dynamically. Any idea How should I do it?

In other words, I want to convert this SQL query to Eloquent:

SELECT * FROM levels
JOIN students on (levels.id = students.level_id)
JOIN examinations on (examinations.level_id = students.level_id AND examination.student_id = students.id)

This is the code I have tried so far.

$levels = Level::with(['students' => function ($query) {
            $query->with(['examination' => function ($inner_query) use ($query) {
                $inner_query->where('level_id', '???');
            }]);
        }])->get();
Oct
16
4 months ago
Activity icon

Replied to Merge Two Queries Into One.

@automica thanks for the recommendation. I have it. Pages are much faster now.

Activity icon

Replied to Merge Two Queries Into One.

I have figured it out. Thank you so much for your efforts, peace be upon you :) This is the code now:

	$orders = Order::with(['product'])
            ->where('orders.store_id', $vendor->store_id)
            ->where('orders.vendor_id', $vendor->wp_vendor_id)
            ->whereIn('orders.status', ['processing', 'pending'])
            ->groupBy(['orders.wp_order_id'])
            ->get();

        foreach($orders as $order) {
            $products = $order->product->groupBy('product_id');

            foreach($products as $product) {

            }
        }

Thank you for your time.

Activity icon

Replied to Merge Two Queries Into One.

I have tried withCount() but it does not return proper data. It returns the just count of all products for one order. I want separate count (also the other product details) for each groupBy('product_id') group.

Activity icon

Replied to Merge Two Queries Into One.

Thanks for the response @automica I have refactored the code and now it looks like this:

Order::with(['product' => function($query) {
                $query->groupBy('product_id');
            }])
            ->where('orders.store_id', $vendor->store_id)
            ->where('orders.vendor_id', $vendor->wp_vendor_id)
            ->whereIn('orders.status', ['processing', 'pending'])
            ->groupBy(['orders.wp_order_id'])
            ->take(10)->get()->toArray()

But when I try to put select in inner/subquery it does not return relation data for product. Here is what I am trying:

Order::with(['product' => function($query) {
                return $query->select([
                    DB::raw('product_name'),
                    DB::raw('count(product_id) as number_of_items')
                ])->groupBy('product_id');
            }])
            ->where('orders.store_id', $vendor->store_id)
            ->where('orders.vendor_id', $vendor->wp_vendor_id)
            ->whereIn('orders.status', ['processing', 'pending'])
            ->groupBy(['orders.wp_order_id'])
            ->take(10)->get()->toArray()

I am using select in subquery because I want the count for each group in the subquery. I hope it makes sense

Activity icon

Started a new Conversation Merge Two Queries Into One.

I am struggling to merge these two queries into a single query. I have tried joins and subquery but could solve this. I am using Laravel, I am executing one query in the Controller and the other in the blade file. Controller code:

$orders = Order::select([
    DB::raw('id'),
    DB::raw('wp_order_id'),
    DB::raw('customer_name'),
    DB::raw('pickup_location'),
    DB::raw('vendor_id'),
    DB::raw('date_created'),
])
->where('orders.store_id', $vendor->store_id)
->where('orders.vendor_id', $vendor->wp_vendor_id)
->whereIn('status', ['processing', 'pending'])
->groupBy(['wp_order_id'])
->get();

Blade code:

@forelse ($orders as $item)
<tr>
<td>
@php
$products = \App\OrderProduct::select([
DB::raw('product_name'),
DB::raw('count(product_id) as number_of_items'),
])
->where('wp_order_id', $item->wp_order_id)
->groupBy('product_id')
->get();
@endphp
@forelse ($products as $product)
{{ $product->number_of_items . ' x ' . $product->product_name }} <br>
@empty
@endforelse
</td>
</tr>
@empty
@endforelse

Kindly help me solve this.