Last active
October 3, 2018 17:26
-
-
Save markheramis/9275949504799c9e0cf0339dc88a4e66 to your computer and use it in GitHub Desktop.
Dirty solution for paginate modification.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"error":false, | |
"data":{ | |
"current_page":2, | |
"data":[ | |
{ | |
"id":5, | |
"path":"\/storage\/1\/brand\/c7523294b7787a124a613a857c9dfc5c.png", | |
"title":"c7523294b7787a124a613a857c9dfc5c", | |
"created_at":"2018-10-03 16:09:03", | |
"updated_at":"2018-10-03 16:09:03" | |
}, | |
{ | |
"id":6, | |
"path":"\/storage\/1\/brand\/4a00deed4b586b788ad3c110638cafa9.png", | |
"title":"4a00deed4b586b788ad3c110638cafa9", | |
"created_at":"2018-10-03 16:09:03", | |
"updated_at":"2018-10-03 16:09:03" | |
}, | |
{ | |
"id":7, | |
"path":"\/storage\/1\/brand\/4206e927aebcf25d6f972757ef80b252.png", | |
"title":"4206e927aebcf25d6f972757ef80b252", | |
"created_at":"2018-10-03 16:09:03", | |
"updated_at":"2018-10-03 16:09:03" | |
}, | |
{ | |
"id":8, | |
"path":"\/storage\/1\/brand\/2306247ddeead450d91ee81d528020fa.png", | |
"title":"2306247ddeead450d91ee81d528020fa", | |
"created_at":"2018-10-03 16:09:03", | |
"updated_at":"2018-10-03 16:09:03" | |
} | |
], | |
"from":5, | |
"last_page":12, | |
"per_page":4, | |
"to":8, | |
"total":46, | |
"prev_page_num":"1", | |
"next_page_num":"3", | |
"last_page_num":"12", | |
"first_page_num":"1" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Return a json array of available Media Brands owned by the current user. | |
* @todo replace request with a custom Laravel Request object todo validation and authorization (implement this on security sprint) | |
* @param MediaGetRequest $request the current HTTP request object. | |
* @return Response a json containing all the files available | |
* @uses App\Models\Media | |
* @uses Illuminate\Http\Response | |
* @uses App\Api\V1\Requests\MediaGetRequest | |
*/ | |
public function getMediaBrand(MediaGetRequest $request) | |
{ | |
$limit = ($request->query('limit')) ? $request->query('limit') : 4; | |
$media = Media::select('id', 'path', 'title', 'created_at', 'updated_at') | |
->where([ | |
'user_id' => Auth::user()->id, | |
'type' => 'brand', | |
]) | |
->paginate($limit); | |
$brand = $media->toArray(); | |
# start Dirty Solution | |
$brand['prev_page_num'] = substr($brand['prev_page_url'], strpos($brand['prev_page_url'], 'page=') + 5, strlen($brand['prev_page_url'])); | |
$brand['next_page_num'] = substr($brand['next_page_url'], strpos($brand['next_page_url'], 'page=') + 5, strlen($brand['next_page_url'])); | |
$brand['last_page_num'] = substr($brand['last_page_url'], strpos($brand['last_page_url'], 'page=') + 5, strlen($brand['last_page_url'])); | |
$brand['first_page_num'] = substr($brand['first_page_url'], strpos($brand['first_page_url'], 'page=') + 5, strlen($brand['first_page_url'])); | |
unset($brand['prev_page_url']); | |
unset($brand['next_page_url']); | |
unset($brand['last_page_url']); | |
unset($brand['first_page_url']); | |
unset($brand['path']); | |
# end Dirty Solution | |
return response()->success($brand); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"error":false, | |
"data":{ | |
"current_page":2, | |
"data":[ | |
{ | |
"id":5, | |
"path":"\/storage\/1\/brand\/c7523294b7787a124a613a857c9dfc5c.png", | |
"title":"c7523294b7787a124a613a857c9dfc5c", | |
"created_at":"2018-10-03 16:09:03", | |
"updated_at":"2018-10-03 16:09:03" | |
}, | |
{ | |
"id":6, | |
"path":"\/storage\/1\/brand\/4a00deed4b586b788ad3c110638cafa9.png", | |
"title":"4a00deed4b586b788ad3c110638cafa9", | |
"created_at":"2018-10-03 16:09:03", | |
"updated_at":"2018-10-03 16:09:03" | |
}, | |
{ | |
"id":7, | |
"path":"\/storage\/1\/brand\/4206e927aebcf25d6f972757ef80b252.png", | |
"title":"4206e927aebcf25d6f972757ef80b252", | |
"created_at":"2018-10-03 16:09:03", | |
"updated_at":"2018-10-03 16:09:03" | |
}, | |
{ | |
"id":8, | |
"path":"\/storage\/1\/brand\/2306247ddeead450d91ee81d528020fa.png", | |
"title":"2306247ddeead450d91ee81d528020fa", | |
"created_at":"2018-10-03 16:09:03", | |
"updated_at":"2018-10-03 16:09:03" | |
} | |
], | |
"first_page_url":"http:\/\/localhost:8000\/api\/media\/brand?page=1", | |
"from":5, | |
"last_page":12, | |
"last_page_url":"http:\/\/localhost:8000\/api\/media\/brand?page=12", | |
"next_page_url":"http:\/\/localhost:8000\/api\/media\/brand?page=3", | |
"path":"http:\/\/localhost:8000\/api\/media\/brand", | |
"per_page":4, | |
"prev_page_url":"http:\/\/localhost:8000\/api\/media\/brand?page=1", | |
"to":8, | |
"total":46 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment