How to understand the Laravel controller?

Welcome! Really confused about the Laravel controllers.

The problem is that I create a form to popolneniya/withdrawals from the balance, creating BalanceController for this and create methods increase (to recharge) and decrease (to remove):

Here is the form:

Form for depositing and withdrawing with balance
{!! Form::model($user, ['method' => 'PATCH', 'action' => ['BalanceController@increase', $user->balance]]) !!}
 {!! Form::token() !!}
 {!! Form::label('amount', 'Enter the amount to recharge') !!}
 {!! Form::text('amount', null, ['class' => 'form-control']) !!}
 {!! Form::submit('Fill', ['class' => 'btn btn-primary']) !!}
 {!! Form::close() !!}

 {!! Form::model($user, ['method' => 'PATCH', 'action' => ['BalanceController@decrease', $user->balance]]) !!}
 {!! Form::token() !!}
 {!! Form::label('amount', 'Enter the amount for withdrawal') !!}
 {!! Form::text('amount', null, ['class' => 'form-control']) !!}
 {!! Form::submit('Remove', ['class' => 'btn btn-primary']) !!}
 {!! Form::close() !!}


Here is my controller:

BalanceController
class Controller extends BalanceController
{

 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 have written:
Action App\Http\Controllers\BalanceController@increase not defined


The ranting I have specified only Route::resource('/profile', 'ProfileController');. Could there be a problem caused by the fact that I do not have to get any links in my Balanscentrale? If Yes, what to specify in the router? Route::get, Route::put, or something else? Thank you in advance for your answers!
June 3rd 19 at 19:09
1 answer
June 3rd 19 at 19:11
Solution
Could there be a problem caused by the fact that I do not have to get any links in my Balanscentrale?
Of course, the problem was caused by this.

If Yes, what to specify in the router? Route::get, Route::put, or something else?
You in the form of a pointed PATCH method.
Thank you very much for the answer!
It turns out I should write here such ranting?
Route::patch('/profile', 'BalanceController@increase');
Route::patch('/profile', 'BalanceController@decrease');

But if I had to error due to the fact that the first parameters ("profile") will be the same in two controllers? I just don't need these parameters were specified this way:
Route::patch('/profile/increase', 'BalanceController@increase');
Route::patch('/profile/decrease', 'BalanceController@decrease');
- pasquale.Schamberg commented on June 3rd 19 at 19:14
Can't have two routes with the same url and method. Either do as in the second your options, either do one method that using post will make the team increase or decrease. - aniya commented on June 3rd 19 at 19:17
Understood, thank you very much - pasquale.Schamberg commented on June 3rd 19 at 19:20
In addition I should add that the named ranting is better to use than a uri to it.
Route::get('/profile/increase', ['as' => 'balance.increase', 'uses' => 'BalanceController@increase']);
- Jamaal_Bode commented on June 3rd 19 at 19:23

Find more questions by tags Laravel