Buy your loved one the ultimate gift. Lifetime gift certificates are $100 off.

fwartnerAY

PHP Lead-Developer at ABOUT YOU GmbH

Experience

1,440

0 Best Reply Awards

  • Member Since 4 Months Ago
  • 13 Lessons Completed
  • 0 Favorites

17th November, 2017

fwartnerAY left a reply on Order By Own Key • 3 weeks ago

UPDATE: Doesn´t work.. It was just because i found a unit on top, thats always on top.. ^^

fwartnerAY left a reply on Order By Own Key • 3 weeks ago

Got it!

fwartnerAY left a reply on Order By Own Key • 3 weeks ago

@vladshoob a user only belongs to one unit. With prepend i get no output =/

fwartnerAY left a reply on Order By Own Key • 3 weeks ago

This is what i have so far.. My application contains a lot of users and units.. A user belongs to a unit.

Normally, the units are ordered by name. Wich is fine for me. But right now, i want to have the unit of the authenticated user right on top of all units. After the unit of the user, i want the other units..

Unit Model:

/**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function users()
    {
        return $this->hasMany(User::class, 'unit_id');
    }

User Model:

/**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function unit()
    {
        return $this->belongsTo(Unit::class, 'unit_id');
    }

In the UnitController:

$units = Unit::with('users', 'circles', 'articles', 'techlead', 'productlead')
                ->withCount('circles')
                ->orderBy('name')
                ->paginate();

fwartnerAY started a new conversation Order By Own Key • 3 weeks ago

Hey everyone..

I have a question regarding to Eloquent´s `orderB method..

Szenario: I have a user. This user belongs to a unit. Now on the unit page, i want to to show all units but the unit of the user should be on top.

How do i order this?

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.