dimanche 19 février 2017

Pass Variable from Component to Model Scope

I'm using OctoberCMS based on Laravel.

I'm trying to get the identifier from URL and pass it to the Scope to filter database results.

$this->property('username') works and returns the username from the URL.

But how do you pass it to the Model and into the Scope function?

Here is the guide, under Dynamic Scopes.

http://ift.tt/2kznJWO

Page

URL: localhost/user/matt

Identifier: /user/:username

Results Component

public function init()
{
    // get username from url
    $username = $this->property('username'); //matt

    // pass username to scope
    Gallery::applyUser($username)->get();
}

Gallery Model

// return results that match username
public function scopeApplyUser($query, $username)
{
    return $query->where('username', $username);
}

Error

Missing argument 2 for MyVendor\Gallery\Models\Gallery::scopeApplyUser()



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mdyPkF
via IFTTT

Aucun commentaire:

Enregistrer un commentaire