Sunday, March 11, 2018

Laravel returns value something else automatically - development

Laravel returns value something else automatically

I am using paginate function in SymbolController which returns data according to page number. The function is returning data in correct form. But, I am using redis as well in which I am storing the returned data but I am missing something it stores complete pagination html content in redis but while returning it returns json correctly. Below is the function:

 public function paginate(Request $request)
    {
        $pageNumber = $request->id;
        $all = self::$redis::get('symbollist:'.$pageNumber);
        if(is_null($all)){
            $symbol = new Symbol();
            $all = $symbol::paginate(10,['*'], 'page', $pageNumber);
            self::$redis::set('symbollist:'.$pageNumber,$all);//store here
        }
        return $all;
    }

How can store value which is returned in redis.

NOTE: The function returns exactly what I require.Only issue is with storing it in Redis

Data returned from API.

{"current_page":1,"data":[{"id":1550,"symbol":"ZYLOG","series":"EQ","isin":"INE225I01026","created_at":"2018-03-11 06:13:27","updated_at":"2018-03-11 06:13:27"},{"id":1549,"symbol":"ZYDUSWELL","series":"EQ","isin":"INE768C01010","created_at":"2018-03-11 06:13:27","updated_at":"2018-03-11 06:13:27"},{"id":1548,"symbol":"ZUARIGLOB","series":"EQ","isin":"INE217A01012","created_at":"2018-03-11 06:13:27","updated_at":"2018-03-11 06:13:27"},{"id":1547,"symbol":"ZUARI","series":"EQ","isin":"INE840M01016","created_at":"2018-03-11 06:13:27","updated_at":"2018-03-11 06:13:27"},{"id":1546,"symbol":"ZOTA","series":"SM","isin":"INE358U01012","created_at":"2018-03-11 06:13:27","updated_at":"2018-03-11 06:13:27"},{"id":1545,"symbol":"ZODIACLOTH","series":"EQ","isin":"INE206B01013","created_at":"2018-03-11 06:13:27","updated_at":"2018-03-11 06:13:27"},{"id":1544,"symbol":"ZICOM","series":"EQ","isin":"INE871B01014","created_at":"2018-03-11 06:13:26","updated_at":"2018-03-11 06:13:26"},{"id":1543,"symbol":"ZENTEC","series":"EQ","isin":"INE251B01027","created_at":"2018-03-11 06:13:26","updated_at":"2018-03-11 06:13:26"},{"id":1542,"symbol":"ZENSARTECH","series":"EQ","isin":"INE520A01019","created_at":"2018-03-11 06:13:26","updated_at":"2018-03-11 06:13:26"},{"id":1541,"symbol":"ZENITHEXPO","series":"EQ","isin":"INE058B01018","created_at":"2018-03-11 06:13:26","updated_at":"2018-03-11 06:13:26"}],"first_page_url":"http://127.0.0.1:8000/api/symbol/1?page=1","from":1,"last_page":155,"last_page_url":"http://127.0.0.1:8000/api/symbol/1?page=155","next_page_url":"http://127.0.0.1:8000/api/symbol/1?page=2","path":"http://127.0.0.1:8000/api/symbol/1","per_page":10,"prev_page_url":null,"to":10,"total":1550}

Data in $all after paginate call.

LengthAwarePaginator {#551 ▼
  #total: 1550
  #lastPage: 155
  #items: Collection {#543 ▶}
  #perPage: 10
  #currentPage: 2
  #path: "http://127.0.0.1:8000/api/symbol/2"
  #query: []
  #fragment: null
  #pageName: "page"
}



from Laravel Questions and Answers https://laravelquestions.com/laravel/laravel-returns-value-something-else-automatically/
via Lzo Media

No comments:

Post a Comment