I have a Laravel 8 project. There is a feature to approve incoming creator references. However, when I press the create button when we want to approve the incoming applications, 500 | It gives a SERVER ERROR error.
When I look from Sentry, it shows the error as follows:
ErrorException creators_store
Undefined variable $user
CreatorController::store
public function store(Request $request){
$request->validate([
'name' => 'required',
'email' => 'required|email'
]);
$subscriber = User::where('email','=',$request->email)->get()->first();
$form_id = $request->form_id;
if($subscriber!=null){
// Already registered user
$subscriber->update([
'role_id' => 3,
'name' => $request->name,
]);
$subscriber = User::findorfail($subscriber->id);
$subscriber->profile_token = env('FRONTEND_PATH').'creator-profile-form?token='.base64_encode($subscriber->email.'/'.$subscriber->id);
Mail::send(['html'=>'email.creators.register'], ['creator' => $subscriber], function($message) use($subscriber){
$message->to($subscriber->email, $subscriber->name)->subject
('Welcome to the Creator Community');
$message->from('creatorcommunity@omnicourse.io','Omnicourse Creator Community');
});
}else{
// New Creator
$pass = random_int(100000, 999999);
$user = User::create([
'name' => $request->name,
'email' => $request->email,
'password' => bcrypt($pass),
'role_id' => 3,
]);
}
if($form_id!=null){
//Formdan geldi
$form = CreatorApplicationForm::findorfail($form_id);
$form->update([
'creator_id' => $user->id
]);
}
return redirect('/admin-panel/creators');
}
It was giving a similar error before, but it was because that mailgun service was not paid for. We paid for the service, but this time it started to give an error like this, but we used the same codes before and it did not give an error. I don't understand why it gives an error even though we haven't made any code changes.
Anyone know the reason or solution for this?