staudenmeir

staudenmeir

Member Since 2 Years Ago

Munich, Germany

Experience Points 84,410
Experience Level 17

590 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 139
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.

25 Apr
1 day ago

staudenmeir left a reply on "SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row

Does the data_text table already contain data when you add the foreign key?

22 Apr
4 days ago

staudenmeir left a reply on Call To A Member Function AddEagerConstraints() On Integer With Scope Function

Your code doesn't work because sum() already executes the query.

Use withCount() instead:

public function scopeWithSum ($query)
{
    return $query->withCount(['relationship as column_sum' => function ($query) {
        $query->select(DB::raw('sum(column)'));
    }]);
}
21 Apr
5 days ago

staudenmeir left a reply on Getting Model's Morph Class Without An Instance

There is no static method for this. Use return (new $morphableType)->getMorphClass();.

20 Apr
6 days ago

staudenmeir left a reply on Eager Loading Null Nested Relationship Causes Memory Error When Null

Can you provide the required steps to reproduce this on a fresh installation?

19 Apr
1 week ago

staudenmeir left a reply on Laravel Collection Merge Removes An Item?

When merging Eloquent collections, models with the primary key are seen as duplicates (even with different classes).

You can prevent this by converting the first one to a base collection:

$collection = $properties->toBase()->merge($advertisements);
18 Apr
1 week ago

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

If you have already defined the intermediate relationships, there is no difference. Theoretically, hasManyDeepFromRelations() is slower, but the difference is basically immeasurable.

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

The relationship with hasManyDeep() would look like this:

public function shipments()
{
    return $this->hasManyDeep(Shipment::class, [Bag::class, 'linked_bags_shipments']);
}
17 Apr
1 week ago

staudenmeir left a reply on Only Getting Accessor Values On Specific Queries

Please post your whole model or the relevant parts.

staudenmeir left a reply on 100k Rows With() Eager Loading Result In - Too Many SQL Parameters?

whereIn() still relies bindings (as it should), but eager loading now uses whereIntegerInRaw() for integer keys.

staudenmeir left a reply on 100k Rows With() Eager Loading Result In - Too Many SQL Parameters?

Are you actually getting this error? Or are you asking a theoretical question?

staudenmeir left a reply on 100k Rows With() Eager Loading Result In - Too Many SQL Parameters?

Normally, Laravel use prepared statements with bindings:

Comment::find(1);

select * from `comments` where `id` = ? limit 1 // Bindings: [1]

Since Laravel 5.7.14, eager loading puts integer keys directly in the query:

select * from `comments` where `comments`.`post_id` in (1, 2, 3)

This way, errors like yours shouldn't be possible anymore.

staudenmeir left a reply on 100k Rows With() Eager Loading Result In - Too Many SQL Parameters?

It is, but Laravel 5.7.14+ doesn't use bindings anymore when eager loading integer keys: https://github.com/laravel/framework/pull/26434

Can you post the Post and Comment models?

staudenmeir left a reply on HasManyThrough 3 Table .

Laravel has no native support for a direct relationship.

I've created a package for cases like this: https://github.com/staudenmeir/eloquent-has-many-deep

class University extends Model
{
    use \Staudenmeir\EloquentHasManyDeep\HasRelationships;

    public function students()
    {
        return $this->hasManyDeep(Student::class, [Campus::class, User::class]);
    }
}
16 Apr
1 week ago

staudenmeir left a reply on Laravel Relation Query Taking Too Much Time To Load

Have you analyzed the query with EXPLAIN? Does the scan_date column have an index?

staudenmeir left a reply on Laravel Relation Query Taking Too Much Time To Load

What does your query look like?

14 Apr
1 week ago

staudenmeir left a reply on Dusk Does Not Execute Button Click & Contenteditable Field Updates Sporadically

Can you create a minimal application to reproduce the issue and upload it somewhere?

12 Apr
2 weeks ago

staudenmeir left a reply on Nested Relationship First Rows

There is no native support for this in Laravel.

I've created a package for it: https://github.com/staudenmeir/eloquent-eager-limit

Use the HasEagerLimit trait in both the parent and the related model.

class DefaultTariffs extends Model {
    use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;
}

class Matrix extends Model {
    use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;
}

Then you can apply ->limit(1) to your relationship.

09 Apr
2 weeks ago

staudenmeir left a reply on How To Check If Dusk Is Running

I don't think there's an elegant method. You can use this:

if (file_exists(base_path('.env.backup'))) {
    // Dusk is running.
}
07 Apr
2 weeks ago

staudenmeir left a reply on Query Builder WhereIn AND WhereNotIn

Please provide some sample data that produces an incorrect result.

06 Apr
2 weeks ago

staudenmeir left a reply on Getting All Product With Avgrating('stars')

You can use withCount():

$products = Product::with('ratings')
    ->withCount(['ratings as avgrating' => function ($query) {
        $query->select(DB::raw('avg(stars)'));
    }])->where('quantity', '>', 0)->get();
05 Apr
3 weeks ago

staudenmeir left a reply on Laravel Update Query Not Working

Have you added the updatable attributes to Bank_details::$fillable?

staudenmeir left a reply on Dusk Selector Not Working

@webspecdesign Does the error screenshot show the correct page?

04 Apr
3 weeks ago

staudenmeir left a reply on WhereRaw Parameter Binding With Postgres Not Working

A binding always has to contain the "whole" value:

User::whereRaw("name like '%?%'", ['foo']) // Doesn't work.
User::whereRaw("name like ?, ['%foo%']) // Works.

That's why I thought this would work:

Device::whereRaw("last_seen_at < NOW() - INTERVAL ?", [$minutes.' minutes'])

But somehow, INTERVAL is a special case on PostgreSQL.

staudenmeir left a reply on LoadMorph A Distant Relation

That's what I've fixed in my answer.

staudenmeir left a reply on LoadMorph A Distant Relation

How do you mean? Are you using something like $users = $users->load('activities')->pluck('activities')?

Note that I've updated my first answer.

staudenmeir left a reply on LoadMorph A Distant Relation

Unfortunately, this is more complicated:

$users->load('activities')->pluck('activities')->flatten()->loadMorph('parentable', ...);

staudenmeir left a reply on WhereRaw Parameter Binding With Postgres Not Working

When Laravel builds the error message, it replaces the placeholders with the actual bindings.

staudenmeir left a reply on WhereRaw Parameter Binding With Postgres Not Working

On PostgreSQL, you can use the binding like this:

Device::whereRaw('last_seen_at < NOW() - ?::interval', [$minutes.' minutes'])->get();
03 Apr
3 weeks ago

staudenmeir left a reply on Enable Json1 Extension For Sqlite3

Judging from the code, it doesn't look like Homestead is actively enabling the JSON1 extension: https://github.com/laravel/settler/blob/master/scripts/provision.sh#L268

02 Apr
3 weeks ago

staudenmeir left a reply on Attaching A Polymorphic Many-to-Many Relationship

Take a look at the documentation:

public function competitors()
{
    return $this->morphedByMany(Player1::class, 'competitor', 'match_competitors', null, 'competitor_id')
        ->using(MatchCompetitor::class);
}

public function competitors()
{
    return $this->morphedByMany(Player2::class, 'competitor', 'match_competitors', null, 'competitor_id')
        ->using(MatchCompetitor::class);
}

staudenmeir left a reply on Attaching A Polymorphic Many-to-Many Relationship

What is MatchCompetitor? The pivot model?

staudenmeir left a reply on Eager Loading Not Working On Many To Many Relationship

Your Programme model has $pivot property that conflicts with the pivot relationship. You'll have to rename it.

staudenmeir left a reply on How Do I Rewrite Such Sql Into Eloquent Style?

What have you tried so far?

staudenmeir left a reply on Attaching A Polymorphic Many-to-Many Relationship

Your relationship is not correct:

public function competitors()
{
    return $this->morphedByMany(MatchCompetitor::class, 'competitor', 'match_competitors', null, 'competitor_id');
}

morphToMany() is meant for the opposite direction.

01 Apr
3 weeks ago

staudenmeir left a reply on Eager Loading Not Working On Many To Many Relationship

Does Programme::first()->reviews work?

31 Mar
3 weeks ago