how to add pagination to this code

Posted 3 months ago by michalis
    $files = File::where('campaign_id', $id);

        if ($month = request('month')) {
            $files->whereMonth('created_at', Carbon::parse($month)->month);

        if ($year = request('year')) {
            $files->whereYear('created_at', $year);

        $files = $files->get()->sortByDesc('created_at');

I tried adding it on the first line but get

Too few arguments to function Illuminate\Support\Collection::get(), 0 passed, at least 1 expected

I tried adding it on the last line and get

Method Illuminate\Database\Eloquent\Collection::paginate does not exist.

Please sign in or create an account to participate in this conversation.