Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 3ce21235

Přidáno uživatelem Marek Zábran před asi 4 roky(ů)

Pokud o paginaci výbrané knihy z charts.

Zobrazit rozdíly:

app/Http/Controllers/ArtefactController.php
117 117
     * @param $id int id of the artefact
118 118
     * @return Factory|View
119 119
     */
120
    public function view($id)
120
    /*public function view($id)
121 121
    {
122 122
        $artefact = Artefact::find($id)->simplePaginate(1);
123 123
        $artefact = $this->prepData($artefact);
124 124
        //return view('artefact.view', ['artefact' => $artefact]);
125 125
        return view('artefact.default', ['artefacts' => $artefact]);
126
    }
126
    }*/
127 127

  
128 128
    /**
129 129
     * Likes artefact given by its id.
......
156 156

  
157 157
        return back()->withInput();
158 158
    }
159

  
160
    /**
161
     * Returns artefact given by its id.
162
     *
163
     * @param $id int id of artefact
164
     * @return RedirectResponse
165
     */
166
    public function view($id)
167
    {
168
        //$user = User::find(Auth::id());
169
        //$artefact = Artefact::find($id);
170

  
171
        $artefacts = Artefact::withCount('users')->orderByDesc('users_count')->get()->take(10);
172

  
173
        $currentPage = -1; // You can set this to any page you want to paginate to
174

  
175
        for($i=0;$i<10;$i++){
176
            if($artefacts[$i]->id==$id) $currentPage = $i+1;
177
        }
178

  
179
        // Make sure that you call the static method currentPageResolver()
180
        // before querying users
181
        \Illuminate\Pagination\Paginator::currentPageResolver(function () use ($currentPage) {
182
            return $currentPage;
183
        });
184

  
185
        $artefacts = Artefact::withCount('users')->orderByDesc('users_count')->limit(10)->paginate(1);
186

  
187
        $artefacts = ArtefactController::prepData($artefacts);
188
        return view('artefact.default', ['artefacts' => $artefacts]);
189
        /*foreach($artefacts as $item)
190
        {
191
            $id = $item->id;
192
            $item['likes'] = Artefact::find($id)->users()->count();
193
            $item['favourite'] = is_null(User::find(Auth::id())->likesArtefacts()->find($id)) ? false : true;
194
        }*/
195

  
196

  
197
        //return back()->withInput();
198
    }
159 199
}

Také k dispozici: Unified diff