小编Ala*_*lik的帖子

Laravel Response内容必须是实现__toString()的字符串或对象,给出"object"

我想运行技能功能,但我不能.

Route.php

Route::get('setting',function(){
    return \App\User::first()->skills();
});
Run Code Online (Sandbox Code Playgroud)

user.php的

protected $casts = [
    'skills' => 'json'
];

public function skills(){
    return new Skills($this , $this->skills);
}
Run Code Online (Sandbox Code Playgroud)

Skills.php

namespace App;
use App\User;
use Mockery\Exception;

class Skills
{
    protected $user;
    protected $skills = [];

    public function __construct(User $user,array $skills){

        $this->user=$user;
        $this->skills=$skills;
    }
}
Run Code Online (Sandbox Code Playgroud)

我想进入/设置页面我有" The Response content must be a string or object implementing __toString(), "object" given."错误.

我尝试dd()在路由中添加函数的返回,我看到所有JSON数据但是$skills->get(),$skill->set()当时没有工作.

编辑:

Skills.php

<?php
    /**
     * Created by PhpStorm.
     * …
Run Code Online (Sandbox Code Playgroud)

php json laravel laravel-4 laravel-5

8
推荐指数
1
解决办法
3万
查看次数

标签 统计

json ×1

laravel ×1

laravel-4 ×1

laravel-5 ×1

php ×1