S
S
SimonPomidorkin2018-07-22 10:17:11
Laravel
SimonPomidorkin, 2018-07-22 10:17:11

How to understand Laravel controllers?

Greetings! Completely confused about Laravel controllers.
The essence of the problem is that I create a form for replenishing / withdrawing money from the balance, creating a BalanceController for this and creating methods increase (for replenishment) and decrease (for withdrawal) in it:
Here is the form:

Form for replenishment and withdrawal from the balance
{!! Form::model($user, ['method' => 'PATCH', 'action' => ['[email protected]', $user->balance]]) !!}
                            {!! Form::token() !!}
                            {!! Form::label('amount', 'Введите сумму для пополнения') !!}
                            {!! Form::text('amount',  null, ['class' => 'form-control']) !!}
                            {!! Form::submit('Пополнить', ['class' => 'btn btn-primary']) !!}
                            {!! Form::close() !!}

                            {!! Form::model($user, ['method' => 'PATCH', 'action' => ['[email protected]', $user->balance]]) !!}
                            {!! Form::token() !!}
                            {!! Form::label('amount', 'Введите сумму для снятия') !!}
                            {!! Form::text('amount',  null, ['class' => 'form-control']) !!}
                            {!! Form::submit('Снять', ['class' => 'btn btn-primary']) !!}
                            {!! Form::close() !!}

Here is my controller:
BalanceController
class BalanceController extends Controller
{

    public function increase(Request $request, $id)
    {
        $user = User::findOrFail($id);
        $amount = $user->balance->amount;
        $balance = $amount + $request->amount;
        $user->balance->update(['amount' => $balance]);
        return redirect('profile');
    }

    public function decrease(Request $request, $id)
    {
        $user = User::findOrFail($id);
        $amount = $user->balance->amount;
        $balance = $amount - $request->amount;
        $user->balance->update(['amount' => $balance]);
        return redirect('profile');
    }

}

The error that I'm getting says:
Action App\Http\Controllers\[email protected] not defined

In my routes, I only have . Could the problem be caused by the fact that I did not specify any links to my BalanceController in the route? If so, what should be specified in the route? Route::get, Route::put or something else? Thanks in advance for your replies! Route::resource('/profile', 'ProfileController');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2018-07-22
@SimonPomidorkin

Could the problem be caused by the fact that I did not specify any links to my BalanceController in the route?
Of course, this is exactly what caused the problem.
If so, what should be specified in the route? Route::get, Route::put or something else?
You have specified the PATCH method in the form.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question