Answer the question
In order to leave comments, you need to log in
How to pass variable from 1 function to another in controller?
I can't pass a variable from 1 controller to another,
there is a function to save the user
public function store(UserRequest $request, User $user)
{
$user->fill($request->only($user->getFillable()));
$user['balance'] = 100;
$user['avatar'] = Storage::put('avatar',$user['avatar']);
$user->password = Hash::make($request->password);
$user->save();
Notification::send($user,new WelcomeNotification);
$this->content = view('Admin::User.verify')
->with([
'title'=>$this->title,
])
->render();
return $this->renderOutPut();
}
<div class="form-group row">
<label for="verification_code"
class="col-md-4 col-form-label text-md-right">{{ __('Phone Number') }}</label>
<div class="col-md-6">
<input id="code" type="tel"
class="form-control @error('verification_code') is-invalid @enderror"
name="verification_code" value="{{ old('verification_code') }}" required>
@error('verification_code')
<span class="invalid-feedback" role="alert">
<strong>{{$message }}</strong>
</span>
@enderror
</div>
</div>
public function verify(Request $request)
{
Хочу сделать проверку,если код из бд совпадает с введенным,редиректить,если нет то сообщение об ошибке
if($request->verification_code == $user->code){
}
}
Answer the question
In order to leave comments, you need to log in
You must remember that when the verify method is run, it is a completely new run of your application, unrelated to the previous one when the store method was executed. In this regard, remembering anything in memory is useless. Every launch of a Laravel application (and any other server-side script) is a clean slate.
In this regard, if you want to work with some information (for example, a user), you need to get it from somewhere. Thus, if you need a user, then you need the user id and in verify you need to get this user from the database by id. Well, then compare what you want.
This means that you must either pass the id through the form along with the verification_code, or, if it is in the route, simply use the Route Model Binding (as is done in the store). In short, you need to understand where $user came from in the store, and then it will become easier for you, but you can understand this only by reading the documentation.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question