staudenmeir

staudenmeir

Member Since 3 Years Ago

Munich, Germany

Experience Points
94,110
Total
Experience

890 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
155
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 19
94,110 XP
21 Sep
1 day ago

staudenmeir left a reply on Query Doesn't Get Executed When Using OrderByRaw()

You need to cast both columns as signed integers:

->orderByRaw('FLOOR(((cast(comment_count as signed) - cast(discussion_count as signed)) * 10 + discussion_count * 21 + votes * 31) / 135) DESC')
31 Aug
3 weeks ago

staudenmeir left a reply on Call To A Member Function GetRelationExistenceQuery() On Array

orWhereHas() doesn't accept an array:

public static function apply(Builder $builder, $value)
{
    return $builder->where('name', 'LIKE', '%' . $value . '%')
        ->orWhereHas('category', function ($q) use ($value) {
            $q->where('name', 'LIKE', '%' . $value . '%');
        });
}
17 Aug
1 month ago

staudenmeir left a reply on HasManyThrough With Pivot

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 Conversation extends Model
{
    use \Staudenmeir\EloquentHasManyDeep\HasRelationships;

    public function users()
    {
        return $this->hasManyDeep(
            User::class,
            [Message::class, 'message_user_pivot']
        );
    }
}

Conversation::find($id)->users;
09 Aug
1 month ago

staudenmeir left a reply on Retrieving Extra Column (computed) In Eloquent Model

If you want to add the computed column to every single query, you can use a global scope: https://laravel.com/docs/eloquent#global-scopes

staudenmeir left a reply on UpdateOrCreate With JSON Fields (MySQL)

It's not very intuitive, but you need to add the whole path to $fillable:

protected $fillable = ['name', 'site_info_json', 'site_info_json->MemberCountyM'];
08 Aug
1 month ago

staudenmeir left a reply on UpdateOrCreate With JSON Fields (MySQL)

Please post the Site model.

06 Aug
1 month ago

staudenmeir left a reply on UpdateOrCreate With JSON Fields (MySQL)

What's the result of dd(Site::updateOrCreate(['short' => 'PHPSUFF'], ['site_info_json->MemberCountyM' => "suffolkkkkkk"])->getAttributes());?

05 Aug
1 month ago

staudenmeir left a reply on UpdateOrCreate With JSON Fields (MySQL)

The current value of site_info_json->MemberCountyM is different from "suffolkkkkkk", right?

04 Aug
1 month ago

staudenmeir left a reply on UpdateOrCreate With JSON Fields (MySQL)

It works for me. Can you log the executed queries?

16 Jul
2 months ago

staudenmeir left a reply on Is There A Without Relationship?

There is:

User::without('posts')->get();
14 Jul
2 months ago

staudenmeir left a reply on Relation Has - Through

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

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

    public function countData()
    {
        return $this->hasManyDeep(
            CountData::class, [Venue::class, Sensor::class]
        );
    }
}

Company::find($id)->countData;
12 Jul
2 months ago

staudenmeir left a reply on Query Builder Search A Json Column

You can use whereJsonContains() with an array:

$products = $products->whereJsonContains('Colors', ['id' => '2']);
11 Jul
2 months ago

staudenmeir left a reply on WhereHas Where Multiple (must Contain)

@hesesses You can also use whereHas()'s third and fourth parameter in combination with whereIn():

$keys = array_keys($request->genres);

$list = Movie::with('genres');

$list->whereHas('genres', function ($query) use ($keys) {
    $query->whereIn('id', $keys);
}, '=', count($keys));

dd($list->limit(3)->get()->toArray());
09 Jul
2 months ago

staudenmeir left a reply on Laravel 5.8 Memory Leak

What does your actual code look like? What are you doing the loop?

04 Jul
2 months ago

staudenmeir left a reply on Laravel 5.8 Memory Leak

I wouldn't call this a memory leak. Your application requires more memory the longer it runs because it has to store more variables.

Case 1 requires more memory because$songs = $album->songs stores the query result in the $album model. The more iterations your loop has, the more memory it requires.

Case 2 behaves differently because it only overwrites the value of $songs with the current query result. The previous results aren't stored anywhere. This keeps the memory usage stable.

Case 3 uses the same amount of memory as case 1 but requires it all at once in the first line.

27 Jun
2 months ago

staudenmeir left a reply on Custom Pivot Table Not Being Respected?

Laravel 5.8:

  public function permissionTypes() {
        return $this->belongsToMany('App\PermissionType', 'people_permissions')->using('App\PersonPermission');
  }

Laravel < 5.8:

  public function permissionTypes() {
        return $this->belongsToMany('App\PermissionType', 'App\PersonPermission');
  }

staudenmeir left a reply on Custom Pivot Table Not Being Respected?

What version of Laravel are you using?

26 Jun
2 months ago

staudenmeir left a reply on (Polymorphic) Many-to-many Relation To Multiple Models

@nbj @roborobok @consil @tobz.nz

I've created a package for merging relationships using views: https://github.com/staudenmeir/laravel-merged-relations

Define the relationships for the different types:

class Competition extends Model
{
    public function teams()
    {
        return $this->morphedByMany(Team::class, 'participant');
    }

    public function users()
    {
        return $this->morphedByMany(User::class, 'participant');
    }
}

Create the merge view in a migration:

use Staudenmeir\LaravelMergedRelations\Facades\Schema;

Schema::createMergeView(
    'participants', [(new Competition)->teams(), (new Competition)->users()]
);

Define the new relationship:

class Competition extends Model
{
    use \Staudenmeir\LaravelMergedRelations\Eloquent\HasMergedRelationships;

    public function participants()
    {
        return $this->mergedRelation('participants');
    }
}

Use it like any other relationship:

Competition::find($id)->participants;

Competition::find($id)->participants()->paginate();

Competition::with('participants')->get();
25 Jun
2 months ago

staudenmeir left a reply on HasManyThrough With MorphMany

Yes, that's the way to go.

staudenmeir left a reply on Eagerly Loaded Relation Not Present In View

Just once it gets passed to the view it is not included anymore in the flight object.

How do you see that? Your view doesn't use the $flight object anywhere.

22 Jun
3 months ago

staudenmeir left a reply on Laravel Dusk Error On Type

Please post the whole stacktrace.

20 Jun
3 months ago

staudenmeir left a reply on SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'issuer' In 'field List'

You can't provide the whole $player object, only its id:

$player->warnings()->create(
    [ 'message' => $faker->text, 'issuer_id' => $player->id ]
);
19 Jun
3 months ago

staudenmeir left a reply on Counting Grandchildren

You can use HasManyThrough by manually adding the likeable_type constraint:

class User extends Model
{
    public function forumLikes(): HasManyThrough
    {
        return $this->hasManyThrough('App\Forum\ForumLike', 'App\Forum\ForumThread', null, 'likeable_id')
            ->where('likeable_type', 'App\Forum\ForumThread');
    }
}

User::withCount('forumLikes')->get();

staudenmeir left a reply on Help Me Understand The Problem With This HasOneThrough Relationship!

The inverse of HasOneThrough is not HasOneThrough but two BelongsTo relationships.

You can use HasOneThrough by swapping foreign and local keys:

public function school()
{
    return $this->hasOneThrough('App\School', 'App\Student', 'id', 'id', 'student_id', 'school_id');
}
16 Jun
3 months ago

staudenmeir left a reply on Laravel One-to-many On PostgreSQL Stops Working

Have a logged the executed queries?

14 Jun
3 months ago

staudenmeir left a reply on Foreign Keys Are Dropping Leading Zeros In Relationships

What's your Laravel version? Can you log the executed queries?

staudenmeir left a reply on Setting Up Dusk With Testing Database

What exact version of Laravel are you using?

11 Jun
3 months ago

staudenmeir left a reply on Using `whereHas` Across Two Databases

Laravel has no native support for this.

You can use a package: https://github.com/hoyvoy/laravel-cross-database-subqueries

08 Jun
3 months ago

staudenmeir left a reply on Performant Way To Mass "update Or Create"

I've created an INSERT & UPDATE (UPSERT) package for all databases: https://github.com/staudenmeir/laravel-upsert

05 Jun
3 months ago

staudenmeir left a reply on Multiple Model Updating

Your raw expressions use backticks to quote column names, but that's the MySQL syntax.

The database you are using (PostgreSQL/SQLite) requires double quotes:

$neighbours->update([
    'left' => DB::raw('"left"+2'),
    'right' => DB::raw('"right"+2'),
]);
03 Jun
3 months ago

staudenmeir left a reply on Conditional INSERT

You can remove the FROM clause like this:

$select = static::query()->from(null)

staudenmeir left a reply on Conditional INSERT

You can use selectRaw():

->selectRaw('?, ?, ?', [$id, $bidId, $bid]);

Does the table actually contain data that matches your constraints?

What's the result of dd($select->get());?

staudenmeir left a reply on Conditional INSERT

What exactly isn't working?

01 Jun
3 months ago

staudenmeir left a reply on Get Latest Value(s) From Every Device Within Tabe

I know these methods by heart, so I'm not sure whether they are all mentioned in the docs.

31 May
3 months ago

staudenmeir left a reply on Get Latest Value(s) From Every Device Within Tabe

whereHas() is for relationships. You need to use whereIn() and a raw expression:

$getsensordata = \App\Sensordata::whereIn('id', function ($query)  {
    $query->selectRaw('max(id)')->from('Sensordata')->groupBy('sensormac');
})->get();

staudenmeir left a reply on Colleges - Do They Get Loaded In Memory At Once?

Yes, all replies get loaded into the memory. What would you expect to happen?

staudenmeir left a reply on Get Latest Value(s) From Every Device Within Tabe

What database and version are you using?

25 May
3 months ago

staudenmeir left a reply on Laravel HasOne() Relationship

Did you install the package?

staudenmeir left a reply on Laravel HasOne() Relationship

What does "doesn't work" mean? Is there an error or are the queries the same as before?

Did you change both models?

staudenmeir left a reply on Laravel HasOne() Relationship

Can you post the whole code of both models?

staudenmeir left a reply on Laravel HasOne() Relationship

What are the executed queries?

24 May
3 months ago

staudenmeir left a reply on Laravel HasOne() Relationship

There is no native support for this in Laravel, as the required query is quite complex.

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

Use the HasEagerLimit trait in both the parent and the related model and apply limit(1) to your relationship:

class MessageType extends Model
{
    use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;

    public function lastMessage()
    {
        return $this->hasOne('App\Message')->latest()->limit(1);
    }
}

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

staudenmeir left a reply on WithCount() / LoadCount() Problem

Use a closure:

Route::bind('userOrder', function ($value) {
    return \App\Order::where('buyer_id', \Auth::id())
        ->where('id', $value)
        ->with([
            'seller' => function ($query) {
                $query->withCount('salesRelevant');
            },
            'product.sub_category.category:id,slug', 'giftCode'
        ])->firstOrFail();
});
20 May
4 months ago

staudenmeir left a reply on N-level Category (self Reference Relation)

Make the relationship recursive:

public function children() {
    return $this->hasMany(Category::class, 'parent_id')->with('children');
}
17 May
4 months ago

staudenmeir left a reply on Issue With Eloquent: API Resources - Conditional Relationships

What's the result of dd($this->getRelations()); in UserResource::toArray()?