Example of Local scopes in PHPJunior/mtube

File app/Models/Channel/Comment.php (link to Github)
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    public function scopeParent($query)
    {
        return $query->where('parent_id', null);
    }
}
File app/Http/Livewire/Frontend/Components/Comment.php (link to Github)
use App\Events\DynamicChannel;
use App\Models\Channel\Video;
use Livewire\Component;
use Livewire\WithPagination;

class Comment extends Component
{
    use WithPagination;

    public $video;
    public $perPage = 5;
    //
    public function mount()
    {
        $this->getData();
    }
    //
    public function getData()
    {
        $this->video = Video::find($this->video_id);
    }

    public function render()
    {
        return view('livewire.frontend.components.comment')->with([
            'comments' => $this->video->comments()->parent()->where('hide', false)->orderBy('created_at', 'desc')->paginate($this->perPage)
        ]);
    }
}

Additional resources on local scopes: