Symfony \组件\调试\异常\ FatalThrowableError(E_ERROR)方法名称必须是字符串

时间:2019-09-25 10:56:06

标签: laravel

当我加载路由127.0.0.1:8000/api/wallet时出现错误

我已经在数据库中完成了播种器,并且没有任何问题

api.php

Route::get('/wallet', 'WalletController@index');
Route::post('/transfer', 'TransferController@store');

WalletController.php

namespace App\Http\Controllers;

use App\Wallet;

class WalletController extends Controller
{
    public function index()
    {
        $wallet = Wallet::firstOrFail();
        return response()->json($wallet->load('transfers', 200));
    }
}

TransferController.php

namespace App\Http\Controllers;

use App\Transfer;
use App\Wallet;
use Illuminate\Http\Request;

class TransferController extends Controller
{
    public function store(Request $request)
    {
          $wallet = Wallet::find($request->wallet_id);
          $wallet->money = $wallet->money + $request->amount;
          $wallet->update();

          $transfer = new Transfer();
          $transfer->description = $request->description;
          $transfer->amount = $request->amount;
          $transfer->wallet_id = $request->wallet_id;
          $transfer->save();

          return response()->json($transfer, 201);


    }
}

我希望屏幕上显示包含信息的json,但会显示错误

Symfony\Component\Debug\Exception\FatalThrowableError thrown with message "Method name must be a string"

Stacktrace:
#47 Symfony\Component\Debug\Exception\FatalThrowableError in C:\xampp\htdocs\walletapp\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php:584
#46 Illuminate\Database\Eloquent\Builder:Illuminate\Database\Eloquent\{closure} in C:\xampp\htdocs\walletapp\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Relations\Relation.php:90
#45 call_user_func in C:\xampp\htdocs\walletapp\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Relations\Relation.php:90

1 个答案:

答案 0 :(得分:1)

Dino Numic给出了答案

这可能是json($ wallet-> load('transfers'),200);中的错字吗?