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.
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.
Because of the working of eloquent it isn't possible to set the scope functions on private.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community