Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel scope function model

public function scopeOwner($query, $id)
{
    return $query->where('user_id', $id);
}

public static function getTicket($id)
{
    $ticket = Support::where('id', $id)->owner(Auth::user()->id)->first();

    return $ticket;
}

You can also do this

public static function getTicket($id)
{
    $ticket = static::where('id', $id)->owner(auth()->id())->first();

    return $ticket;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #laravel #scope #function #model
ADD COMMENT
Topic
Name
1+2 =