0

The error appears when I load route 127.0.0.1:8000/api/wallet

I have already done the seeder in DB and I did not have any problem

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);


    }
}

I expected a json in my screen with the information but show me the error

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
  • 2
    could it be a typo in json($wallet->load('transfers'), 200); Commented Sep 25, 2019 at 10:59

1 Answer 1

1

Dino Numic had the answer

could it be a typo in json($wallet->load('transfers'), 200);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.