大佬们求解啊。我在开发api中遇到了问题,因为要用到redis的list导致数据不能用response方法,具体代码如下:
` public function show($id)
{
// redis连接,判断键时候存在,存在直接输出,不存在在list方法写入
//解决response输入到lessontransformer就ok了
$redis = Redis::connection('default');
if($redis->exists('lesson:profile:'.$id)){
$lesson = $redis->lrange('lesson:profile:'.$id, 0 ,4);
return $this->response->item($lesson,new LessonTransformer());}
else{
$title = Lesson::find($id)->title;
$body = Lesson::find($id)->body;
$auth = Lesson::find($id)->auth;
$comment = Lesson::find($id)->comment;
$created_at = Lesson::find($id)->created_at;
$redis->lpush('lesson:profile:'.$id, $title);
$redis->lpush('lesson:profile:'.$id, $body);
$redis->lpush('lesson:profile:'.$id, $auth);
$redis->lpush('lesson:profile:'.$id, $comment);
$redis->lpush('lesson:profile:'.$id, $created_at);
// 获取存储的数据并输出
$lesson = $redis->lrange('lesson:profile:'.$id, 0 ,4);
echo "Stored string in redis";
print_r($lesson);
}`
报错如下:
"message": "get_class() expects parameter 1 to be object, array given"
用了item,collection等都没用
这是print-r下来的数据
Array ( [0] => 2017-08-03 02:10:31 [1] => 5 [2] => Beatae temporibus facere sunt hic. [3] => Quisquam sunt neque corporis rerum enim ullam esse. Eos quia enim ducimus adipisci quia. Veritatis dolores aut neque esse. [4] => Consequuntur voluptatem sed enim unde. )
请问怎么办呢 @JellyBool