croftCoder

Member Since 1 Year Ago

Experience Points
540
Total
Experience

4,460 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
540 XP
Apr
17
3 weeks ago
Activity icon

Replied to RelatedSameModel Relationship

@fylzero the unique is to ensure that no record is duplicated. and this

return $query->where('id', '<>', $id); // $id or $this->id of current post

returns all posts in the database.

Apr
16
3 weeks ago
Activity icon

Replied to RelatedSameModel Relationship

@fylzero currently this is how i get the related posts

$post->load(['categories.posts' => function ($query) use ( &$relatedPosts ) {
    $relatedPosts = $query->where('posts.id', '<>', $id)->get()->unique()
}]);

return view('posts.show', compact('post', 'relatedPosts'));

but i don't want it as a separate variable but as a model attribute loaded with each post.

class Post {
    public function scopeRelatedPosts($query) {
        // like so? from your answer
        return $query->where('posts.id', '<>', $id)->get()->unique();
    }
}

a related post is a post item that shares common tags and categories with another post. i also want to be able to sort the related posts based on number of tags and categories in common.

Apr
15
3 weeks ago
Activity icon

Started a new Conversation RelatedSameModel Relationship

referencing this discussion, https://laracasts.com/discuss/channels/general-discussion/how-to-get-related-items-from-a-many-to-many-polymorphic-relationship

is it possible to make the $relatedPosts a model relationship such that it's automatically loaded like so

// post model
class Post {
    // relationship setup
    // has many related posts
}

// related post model
class RelatedPost {
    // relationship setup
    // belongs to many posts
}

// in blade view
$post->relatedPosts

how can this be improved as to add other parameters like categories, etc.

Activity icon

Replied to How To Get Related Items From A Many To Many Polymorphic Relationship

great! is it possible to make the $relatedPosts a model relationship such that it's automatically loaded like so

// post model
class Post {
    // relationship setup
}

// related post model
class RelatedPost {
    // relationship setup
}

// in blade view
$post->relatedPosts
Activity icon

Replied to Randomly Add Between X And Y Number Of Comments In Seeder To A Model

great! i'm able to add the comments but it adds 3 comments to all Business models, what i actually want is to add varying number of comments like so:

public function run() {
    $categories = Category::all();

    // create x number of businesses
    // add between 0 to 5 comments on each: min-max
    Business::factory(10)->hasReviews(rand(0, 5))->create()->each(function($business) use ($categories) {
        $business->categories()->attach(
            $categories->random(rand(1, 3))->pluck('id')->toArray()
        );
    });
}
Activity icon

Started a new Conversation Randomly Add Between X And Y Number Of Comments In Seeder To A Model

I have a polymorphic Comment Model and want to seed data inside the BusinessSeeder. how do i randomly add between 1 or 3 comments in the BusinessSeeder and attach to random users?

// Comment Model

Comment
    - id
    - body
    - commentable_id
    - commentable_type
    - user_id

// BusinessSeeder

public function run()
    {
        $categories = Category::all();

    	// create x number of businesses
        Business::factory(5)->create()->each(function($business) use ($categories) {
            $business->categories()->attach(
                $categories->random(rand(1, 3))->pluck('id')->toArray()
            );

            // create x number of comments...
        });
    }
Activity icon

Replied to Switching Account Types Between User And Business Page

@gitwithravish, yeah i want the role-permission kind of architecture. i already have the spatie/laravel-permission package in the project. have added the spatie package to the user model already, as some users can also be made moderators of a business page. i just want to be able to separate the account type interacting in the application. thanks, great help

Activity icon

Replied to Switching Account Types Between User And Business Page

@martinbean, great explanation, i get the concept now. thanks. i can implement the routes and middleware side of it but how do i setup the "actor" aspect. i understand the concept of polymorphic relationship. do i create something like this:

class Actor extends Model {
    // make polymorphic: actorable_id, actorable_type
}
User Model
    - id
    - email
    - password

Business Model
    - id
    - name
    - user_id
Activity icon

Started a new Conversation Switching Account Types Between User And Business Page

Have an application where a user can have a business page like Instagram or Facebook. my challenge is how to get the user user to be able to switch between their personal account and business account, and what they do is restricted by the active login or account type. for example User A has a Business ABC Page, logged in as a user they can comment on products, like a business page but as a business they can't like another business page

problem 1. how to switch between account types, User or Business?

problem 2. allow permission based on active account type

problem 3. remember the last account type used

any ideas or ways to solve these? where to start

Apr
14
3 weeks ago
Activity icon

Replied to Select Distinct Categories Using HasManyThrough With Or Without Pivot Model

no please. this is what i want to achieve

Regions
| id | name     |
-----------------
| 1  | region A |
| 2  | region B |

Districts
| id | name       | region_id |
-------------------------------
| 1  | district A | 1         |
| 2  | district B | 1         |
| 3  | district C | 2         |

Categories
| id | name       |
-------------------
| 1  | category A |
| 2  | category B |
| 3  | category C |

Businesses
| id | name       | district_id |
---------------------------------
| 1  | business A | 1           |
| 2  | business B | 2           |
| 3  | business B | 1           |

Business_Categories
| business_id | category_id |
-----------------------------
| 1           | 1           |
| 1           | 3           |
| 2           | 1           |
| 2           | 2           |
| 2           | 3           |
| 3           | 3           |

how do i select the various categories without duplicates (unique) in a district through the businesses in that district

[district A]->categories should return only [category A and category C]

[district B]->categories should return [category A, category B and category C]

[district C]->categories should return []

or any other way i can achieve this in Laravel?

Activity icon

Started a new Conversation Select Distinct Categories Using HasManyThrough With Or Without Pivot Model

working on a directory listings app and faced with this scenario: how do I select the various categories through the businesses found in a district and the same for a region as well without duplicates?

models and relationships are as follows:

Region => hasMany District
District => belongsTo Region, hasMany Business
Business => belongsTo District, belongsToMany Category
Category => belongsToMany Business

below is my database setup

region:
    id

district:
    id
    region_id

business:
    id
    district_id

category:
    id

business_category:
    business_id
    category_id