webdevelop

Member Since 2 Weeks Ago

Experience Points
180
Total
Experience

4,820 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 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
180 XP
Feb
24
1 week ago
Activity icon

Replied to How To Show To Handle Enums In Laravel?

I am not oxbir.

I don't know oxbir.

Activity icon

Started a new Conversation How To Show To Handle Enums In Laravel?

I like to keep the values for all of these in a central place. For example, I might have an enum that looks like this:

$mobies = [
    'APPLE' => "Apple",
    'SUM' => "Sumsung",
    'LG' => "LG",
];

Which I want to use in both my view/template:

migrate table

Schema::create('products', function (Blueprint $table) {
    $table->id;
    $table->enum('mobiles',['apple','sumsung','lg']);
    ...
});

config/enums.php

<?php

return [
    'mobiles' => [
        'APPLE' => "Apple",
        'SUM' => "Sumsung",
        'LG' => "LG",
    ];
];

index.blade.php

{{ config('enums.reportableTitle') }}

How to show in a blade when it saves in the database.

Feb
23
1 week ago
Activity icon

Replied to Laravel Form Collective Select Option For Edit Selected

I did not know them.

What are they?

Activity icon

Replied to Laravel Form Collective Select Option For Edit Selected

@michaloravec

I did not know them.

What are they?

Activity icon

Started a new Conversation Laravel Form Collective Select Option For Edit Selected

I want to populate the whole Edit form, but SelectBox does not grab the value and always stays on the first one.

{!! Form::select('plaintiff_id', \Modules\User\Entities\User::pluck('name', 'id')->toArray(), 'selected', [
'class' => 'form-control',
'id' => 'name',
'placeholder' => 'name',
]) !!}
Feb
15
2 weeks ago
Activity icon

Started a new Conversation Counting Amount Of Products In Category Not Working In Laravel

I started a project almost a month ago and created a simple table structure for handling categories with "self-referencing association" if you can call it that.

public function up()
{
    Schema::create('categories', function (Blueprint $table) {
        $table->id();
        $table->foreignId('parentId')->nullable()->constrained('categories')->cascadeOnDelete();
        $table->unsignedBigInteger('guildId')->nullable();
        $table->string('title');
        $table->bigInteger('count')->default(0);
        $table->string('type')->default('product')->index();
        $table->string('slug')->unique();
        $table->text('description')->nullable();
        $table->text('full_description')->nullable();
        $table->unsignedBigInteger('sort_order')->nullable();
        $table->foreignId('thumbnailId')->nullable()->constrained('files')->nullOnDelete();
        $table->enum('status', ['disabled', 'enabled'])->default('enabled');
        $table->timestamps();
    });
}

The model itself is also really simple.

public function parent()
{
    return $this->belongsTo(Category::class, 'parentId');
}

public function parents()
{
    return $this->belongsTo(Category::class, 'parentId')->with('parents');
}

public function children()
{
    return $this->hasMany(Category::class, 'parentId');
}

public function products()
{
    return $this->hasMany(Product::class, 'rootCategoryId');
}

public function allProducts()
{
    return $this->belongsToMany(Product::class, 'category_product', 'categoryId', 'productId');
}

This works just fine, but I need now some functionality that is hard to make it work with this kind of table structure. Btw, only leaf-categories or final categories contain products/items. Three is no requirement to fetch products by landing in the middle of the tree. Only the total count of products from that category node and down.

What can't be done (or I didn't figure out yet how to)

  • Counting total products from the root category down to (or up from) the leaf-categories.
  • Landing in the middle of the category tree and counting products down (or up from) the leaf categories children.
  • While products are inactive (I have global and local scopes for this), some category children will be empty. Those must not be displayed or fetched from the database.

Also, keep in mind that I currently have 7 root or top categories from which the tree unfolds or think of it as 7 branches of categories and sub-categories. Those 7 roots do not have a parent_id, it is either null or 0, meaning they don't belong to a "master" parent.

Product.php

class Product extends Model
{
    public function category()
    {
        return $this->belongsTo(Category::class); // products table has the category_id column
    }
}

Some expected results would be like the following. Landing on the "index" should render the 7 categories (or any number of root categories) with the total product count.

  • Category 1 (600 products)
  • Category 1 (500 products)
  • ...
  • Category nth (x products)

If you land in the middle of the category tree it should function similarly.

From Category 1 let's say it's immediate children which is also not a leaf category, but a parent to others.

category

etc, I hope this makes sense.

It is also not required to be "unfolded" like that, I've only placed children of children for this example just for simplicity and to understand the structure. Whenever you land in the middle of the tree, it requires to render only the immediate children of that category node, with the count of total products (including the landed parent)

For example:

If landed on Category 1, only render the immediate children

Title of parent: Parent Category Name (X products)

  • Child 1 (x products)
  • Child 2 (x products)
  • ...
  • Child nth (x products)

My category structure can go very deep, it's very detailed and it is a requirement to be very very specific like that. I have a total of 3200 categories containing 2.4m products. if you wonder about performance issues. Some categories are completely empty. but are there waiting to be filled.

Is it even possible with this single-table structure to do what I require? I feel burned and can't think of a way anymore how to solve this.

Sorry for the long post, I hope someone could help me figure this out.

Controller.php

public function index(Request $request)
{
    $query = Category::ofType($this->type)->with('parent')->with('products')->orderBy('title');
    if ($request->filled('search') ) {
        if (is_numeric($request['search']) ) {
            $query->where('id', 'LIKE', "%${request['search']}%");
        } else {
            $query->where('title', 'LIKE', "%${request['search']}%");

            $query->orWhereHas('parent', function ($query) use ($request) {
                return $query->where('title', 'LIKE', "%${request['search']}%");
            });
        }
    }
    
    return view('category::admin.index', [
    'categories' => $query->paginate(20)->appends($request->except('page')),
    ]);
}

index.blade.php

@php
    function plusCountCategory( &$category ) {
    foreach($categories as $category){
    
    if( !! $category["parentId"] )
    {
    $category["count"] = $category["count"] + 1 ;
    plusCountCategory($category["parentId"] ) ;
    }
    }
    }
@endphp

It has an error

count