laravel 中的未定义变量 $request
Undefined variable $request in laravel
未定义变量 $request
我试图同时插入和更新 2 个表,但出现以下错误 Undefined variable $request
这是我的控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Account;
use App\Models\User;
use App\Models\Transfer;
use DB;
use Auth;
class TransferController extends Controller
{
public function transferform(Request $request)
{
$user = Auth::user();
$accounts = User::find($user->id)->accounts;
$senderAccountId = $accounts->first()->id;
$amount = $request->input('amt');
DB::transaction(function () use ($amount, $senderAccountId) {
$transfer = new Transfer();
$transfer = $amount;
$transfer = $senderAccountId;
$transfer->actype = $request->input('actype');
$transfer->acnumber = $request->input('acnumber');
$transfer->to_acc_name = $request->input('to_acc_name');
$transfer->amt = $amount;
$transfer->Frequency = $request->input('Frequency');
$transfer->acbalance = $request->input('acbalance');
$transfer->discription = $request->input('discription');
$transfer->status = 'pending';
$transfer->save();
$senderAccount = Account::where('id', '=', $senderAccountId)->first();
$senderAccount->acnumber =- $amount;
$senderAccount->save();
Account::query()->findOrFail($senderAccountId)->increment('balance', $amount);
$transfer->status = 'complete';
$transfer->save();
});
}}
这是我的路线:
Route::post('transfer-form', [TransferController::class, 'transferform']);
通过后是这样
DB::transaction(function () use ($amount, $senderAccountId, $request) {
我收到以下错误:
Attempt to assign property "actype" on int
注意这部分。您已将其重新分配给其他东西。 $transfer
值已被覆盖。
$transfer = new Transfer();
$transfer = $amount;
$transfer = $senderAccountId;
// try change to
$transfer = new Transfer();
$transfer->amt = $amount;
$transfer->senderAccountId = $senderAccountId;
未定义变量 $request 我试图同时插入和更新 2 个表,但出现以下错误 Undefined variable $request
这是我的控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Account;
use App\Models\User;
use App\Models\Transfer;
use DB;
use Auth;
class TransferController extends Controller
{
public function transferform(Request $request)
{
$user = Auth::user();
$accounts = User::find($user->id)->accounts;
$senderAccountId = $accounts->first()->id;
$amount = $request->input('amt');
DB::transaction(function () use ($amount, $senderAccountId) {
$transfer = new Transfer();
$transfer = $amount;
$transfer = $senderAccountId;
$transfer->actype = $request->input('actype');
$transfer->acnumber = $request->input('acnumber');
$transfer->to_acc_name = $request->input('to_acc_name');
$transfer->amt = $amount;
$transfer->Frequency = $request->input('Frequency');
$transfer->acbalance = $request->input('acbalance');
$transfer->discription = $request->input('discription');
$transfer->status = 'pending';
$transfer->save();
$senderAccount = Account::where('id', '=', $senderAccountId)->first();
$senderAccount->acnumber =- $amount;
$senderAccount->save();
Account::query()->findOrFail($senderAccountId)->increment('balance', $amount);
$transfer->status = 'complete';
$transfer->save();
});
}}
这是我的路线:
Route::post('transfer-form', [TransferController::class, 'transferform']);
通过后是这样
DB::transaction(function () use ($amount, $senderAccountId, $request) {
我收到以下错误:
Attempt to assign property "actype" on int
注意这部分。您已将其重新分配给其他东西。 $transfer
值已被覆盖。
$transfer = new Transfer();
$transfer = $amount;
$transfer = $senderAccountId;
// try change to
$transfer = new Transfer();
$transfer->amt = $amount;
$transfer->senderAccountId = $senderAccountId;