DPlachkov

DPlachkov

Member Since 4 Months Ago

Experience Points 450
Experience Level 1

4,550 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 2
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.

18 Apr
2 months ago

DPlachkov left a reply on HasManyThrough Using A Pivot On The Second Model.

@STAUDENMEIR - I tried to do it like the given example in the readme. I guess i should have put the pivot at second place in the array

public function permissions()
    {
        return $this->hasManyDeep('App\Permission', ['role_user', 'App\Role']);
    }

Anyway is there any benefit to using hasManyDeep over hasManyDeepFromRelations, because hasManyDeepFromRelations seems clearer to read and understand ( meaning that i have already defined those relationships, why not use them ) I guess even if there was some performance difference it would be minuscule .

DPlachkov left a reply on HasManyThrough Using A Pivot On The Second Model.

Ok i found the solution ( i can't seem to delete this post)

It is to use Staudenmeir's https://github.com/staudenmeir/eloquent-has-many-deep

and then just define a relationship like so

    public function shipments()
    {
        return $this->hasManyDeepFromRelations($this->bags(), (new Bag)->shipments());
    }

I guess there is another way to do it through the hasManyDeep method, but it tries to put the pivot table on the expedition-bags , instead of the bags-shipments tables, so i used the example form above.

DPlachkov started a new conversation HasManyThrough Using A Pivot On The Second Model.

Hello guys i have 3 classes

class Expedition extends Model
{
    public function bags()
    {
        return $this->hasMany(Bag::class);
    }

    public function shipments()
    {
        return $this->hasManyThrough(Shipment::class, Bag::class);
    }
}
class Bag extends Model
{
public function expedition()
    {
        $this->belongsTo(Expedition::class);
    }

    public function shipments()
    {
        return $this->belongsToMany(Shipment::class, 'linked_bags_shipments', 'bag_id', 'shipment_id');
    }
}

And the Shipments class.

What I'm trying to do is call the $expedition->shipments() method, but it doesnt work, since its trying to get it through joining the bags and shipments table, at that model I am using a pivot table called "linked_bags_shipments" . Is there a way to use the hasManyThrough with a pivot table between the 2 models

DPlachkov left a reply on Nested Relationship First Rows

@STAUDENMEIR - Ok thanks I'll give it a shot, It seems that you have created a library for all my Eloquent problems :D. Great job

12 Apr
3 months ago

DPlachkov started a new conversation Nested Relationship First Rows

Hello guys, I have an Eloquent problem that i can't seem to solve.

I'm trying to get the first rows only of my nested relationship product.defaultTariffs.matrix

I have 3 models - Product - defaultTariffs - Matrix A product can have 2 defaultTariffs A defaultTariffs can have multiple values in the Matrix table Matrix table has lets say a hundred rows for a given tariff_id

Matrix table has tariff_id, country_id, kilogram, value

What im tryng to do is

$products = Product::with(['defaultTariffs' => function($query) use ($weight) {
            $query->with(['matrix' => function ($query) use ($weight) {
                $query->where([
                    ['country_id', $_POST['country_id']],
                    ['kilogram', '>=', $weight],
                ])->orderBy('kilogram', 'asc')->limit(1);
            }]);
        }])->get();

The problem is that if i do that the query is built like this

select * from `tariff_matrix` where `tariff_matrix`.`tariff_id` in (1, 2) and (`country_id` = ? and `kilogram` >= ?) order by `kilogram` asc limit 1

And this returns only a single row for a single. If i remove the

->limit(1)

I get all the hundred rows for each defaultTariff

The question is - is there a way for me to eager load only the first row of the nested relationship (the matrix table)

25 Mar
3 months ago

DPlachkov left a reply on Turning Many To Many Relationship - To - HasMany - As Comma Separated Values

Ok, I gave your library a shot and it seems really good. The only question I have is: I'm gonna save only the ids, which as i see is done as an array, when i detach every connection i get left with an empty array in the field. Now this doesn't seem to be a problem, since checking $this->field will return false on an empty array. My question is - is this the expected behavior or should i somehow set the db json column field to null

$object->errorsObj()->detach()->save();

makes it an empty array []

14 Mar
4 months ago

DPlachkov started a new conversation Eager Loading A Conditional Relationship

Hello guys. I've had this problem for a while. I have a Model named "Customer". Its the model that holds the user data. But we have 2 types of users . One is referred as a "customer" which is a main account, while the other one is referred as a "user", which is a sub-account to the main one. I also have senders. Senders are created by the Customer - so he hasMany senders, But the "User" has to be linked to the "senders" with a pivot table, so he belongsToMany. Now this makes my "senders()" relationship a conditional one - dependent on the rank. Currently this works ok if i have preloaded the $customer, so i can then say $customer->senders and it will resolve its senders cause it is already aware of its own rank. But when i try to eager load the customer with its senders, it is failing, because there is no "rank" yet - it is null. Is there a way to make this work with eager loading ?

class Customer extends Model
{
 public function users()
    {
        return $this->hasMany(Customer::class, 'parent_id');
    }

    public function customer()
    {
        return $this->belongsTo(Customer::class, 'parent_id');
    }

  public function senders()
    {
        if ($this->rank == 'user') return $this->hasMany(Senders::class, 'acc_id');

        if ($this->rank == 'sender_user') return $this->belongsToMany(Senders::class, 'linked_senders_users', 'user_id', 'sender_id');
    }
}

This is the senders class

class Senders extends Model
{
 public function customer()
    {
        return $this->belongsTo(Customer::class, 'acc_id');
    }

    public function users()
    {
        return $this->belongsToMany(Customer::class, 'linked_senders_users', 'sender_id', 'user_id');
    }
}

DPlachkov left a reply on Turning Many To Many Relationship - To - HasMany - As Comma Separated Values

Thanks for the suggestion. Ill consider it, but i was wondering is there no other way to use it like passing "explode(column_name)" as the key or something

20 Feb
4 months ago

DPlachkov started a new conversation Turning Many To Many Relationship - To - HasMany

Hello guys. I have this problem with a relationship i want to save differently.

I have the Shipments, and Errors. Now we have some validation and if a shipment does not pass a given validation an error should be added to it. This would normally be a many to many relationship with 2 belongsToMany() relationship, however I want to save the errors.id 's on the shipment table as comma separated values, and then later access the errors() by exploding the shipments.errors column using some mutator/accessor/localScope. Is there a way to do this ?