I am inserting a form data into a database, after successful submission I want to redirect to the leads page.
HTML Form:
<form method="post" action="{{url('lead-message')}}">
{{csrf_field()}}
<input type="hidden" name="lead_id" value="{{$leads->id}}">
<div class="form-group">
<label for="exampleFormControlTextarea1">Type your message*</label>
<textarea class="form-control" name="lead_message" id="lead_message" rows="3" value="" required></textarea>
</div>
<button type="submit" class="btn btn-primary">Send Message</button>
</form>
Route:
Route::group( ['middleware' => ['auth', 'phoneverified']], function() {
Route::resource('leads', 'LeadsController');
});
Controller:
public function leadMessage (Request $request) {
$validate = $request->validate([
'lead_message' => 'required',
]);
$storeMessage = new LeadMessage;
$storeMessage->lead_id = $request->lead_id;
$storeMessage->message = $request->lead_message;
$storeMessage->save();
Session::flush('success', 'Message sends successfuly!');
return redirect('leads/'.$request->lead_id);
}
But after successful submission, it redirects to the login page instead of the leads page and when I logged in again, it directly redirects me to the leads page.
I don't know where I am going wrong. I would appreciate any help in this regard.