Adcade

Adcade

Member Since 1 Month Ago

Experience Points 120
Experience Level 1

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 Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

03 May
1 month 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)

user_id
    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?

24 Apr
1 month 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 ID of an element 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?