Adcade

Adcade

Member Since 4 Months Ago

Experience Points
120
Total
Experience

4,880 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
120 XP
03 May
4 months ago

Adcade left a reply on Many To Many Relationship With Roles

@NAKOV - Worked like a charm. Thank you

Adcade left a reply on Select Sum Of Realtion's Attributes In Query

Maybe using appends could work.

In your Order model, add`

protected $appends = ['paid_from_customer'];

public function getPaidFromCustomerAttribute()
{
    return Revenue::where([['order_id', $this->id],['is_paid', true]])->sum('price'); 
}

(the return query may need to be adjusted to your structure)

Adcade started a new conversation Many To Many Relationship With Roles

I have the tables users, communities and community_user

community
    id
    ... (other columns)

user
    id
    ... (other columns)

community_user
    id
    community_id
    user_id
    role

I want to create relationships so an user can belong to many communities and have a different role on each one (admin, member, etc).

How should I define my models? Can a many-to-many relationship have a key?

24 Apr
4 months ago

Adcade started a new conversation Eloquent OneToMany Relationship With Multiple Possible Columns

I have the following tables:

  • categories: id, name
  • products: sku, name, category1, category2, category3

Where category 1, 2 and 3 are the IDs of different elements in categories table.

I need to define a relationship where a product can have the category id in ANY of the three columns. Right now my models are:

class Category extends Model
{
    protected $fillable = [
        'id',
        'name',
    ];

    public function products()
    {
        return Product::where('category1', $this->id)->orWhere('category2', $this->id)->orWhere('category3', $this->id)->get();
    }
}
class Product extends Model
{
    protected $primaryKey = 'sku';

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

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

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

But anytime I try to get the products that belong in a category (1, 2 or 3), I get the error

LogicException with message 'App/Category::products must return a relationship instance.'

How should I define the products() function?