Support the ongoing development of Laravel.io →
posted 6 years ago
Eloquent
Last updated 2 years ago.
0
moderator

I don't understand the reason that you want to add the scope functions as private. The scope is used to create a query, that will be done from outside of the class so that shouldn't be private.

Also the function shouldn't be static, see https://laravel.com/docs/5.6/eloquent#local-scopes for more information.

0

Sorry, It is necessary to define some methods to access scopeSample...

use Illuminate\Database\Eloquent\Model;

class Test extends Model {

    private static function scopeSample($query) {

        return $query->where('name');
    }

    public static function getTable() {
        $table = self::sample()
        ->get();

        return $table;
    }

     public static function getTableCount() {
        $table = self::sample()
        ->get();

        if ($table->count() === 0) {
            return false;
        }
        else
        {
            return true;
        }
    }
}

Actually I want to share the scope with different public methods.
I'm sorry for confusing you.

0
moderator

Because of the working of eloquent it isn't possible to set the scope functions on private.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.