Laravel - form action after authentication












0














I'd like to know how I can send my form to a method when the auth middleware comes in the way.



When I submit the form, auth middleware checks if the user is logged in. If not the user will be asked to log in. After a successful login, the user will be redirected to the form.
But I like the form to be sent once the login was successful.



Can anyone tell me what needs to be done to archive this?



Thanks in advance!



Andreas










share|improve this question






















  • Is there any reason why you don't authenticate the user before he can access the form?
    – Remul
    Nov 21 '18 at 15:13










  • @Remul Yeah, there is. It's a form where you can create a setup for a character for a game and see the benefits of the items. This feature should be available for just everyone. But when the user wanna save the config he has to be logged in.
    – Andreas B
    Nov 21 '18 at 15:20


















0














I'd like to know how I can send my form to a method when the auth middleware comes in the way.



When I submit the form, auth middleware checks if the user is logged in. If not the user will be asked to log in. After a successful login, the user will be redirected to the form.
But I like the form to be sent once the login was successful.



Can anyone tell me what needs to be done to archive this?



Thanks in advance!



Andreas










share|improve this question






















  • Is there any reason why you don't authenticate the user before he can access the form?
    – Remul
    Nov 21 '18 at 15:13










  • @Remul Yeah, there is. It's a form where you can create a setup for a character for a game and see the benefits of the items. This feature should be available for just everyone. But when the user wanna save the config he has to be logged in.
    – Andreas B
    Nov 21 '18 at 15:20
















0












0








0







I'd like to know how I can send my form to a method when the auth middleware comes in the way.



When I submit the form, auth middleware checks if the user is logged in. If not the user will be asked to log in. After a successful login, the user will be redirected to the form.
But I like the form to be sent once the login was successful.



Can anyone tell me what needs to be done to archive this?



Thanks in advance!



Andreas










share|improve this question













I'd like to know how I can send my form to a method when the auth middleware comes in the way.



When I submit the form, auth middleware checks if the user is logged in. If not the user will be asked to log in. After a successful login, the user will be redirected to the form.
But I like the form to be sent once the login was successful.



Can anyone tell me what needs to be done to archive this?



Thanks in advance!



Andreas







laravel laravel-5 laravel-5.7






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 15:00









Andreas B

529




529












  • Is there any reason why you don't authenticate the user before he can access the form?
    – Remul
    Nov 21 '18 at 15:13










  • @Remul Yeah, there is. It's a form where you can create a setup for a character for a game and see the benefits of the items. This feature should be available for just everyone. But when the user wanna save the config he has to be logged in.
    – Andreas B
    Nov 21 '18 at 15:20




















  • Is there any reason why you don't authenticate the user before he can access the form?
    – Remul
    Nov 21 '18 at 15:13










  • @Remul Yeah, there is. It's a form where you can create a setup for a character for a game and see the benefits of the items. This feature should be available for just everyone. But when the user wanna save the config he has to be logged in.
    – Andreas B
    Nov 21 '18 at 15:20


















Is there any reason why you don't authenticate the user before he can access the form?
– Remul
Nov 21 '18 at 15:13




Is there any reason why you don't authenticate the user before he can access the form?
– Remul
Nov 21 '18 at 15:13












@Remul Yeah, there is. It's a form where you can create a setup for a character for a game and see the benefits of the items. This feature should be available for just everyone. But when the user wanna save the config he has to be logged in.
– Andreas B
Nov 21 '18 at 15:20






@Remul Yeah, there is. It's a form where you can create a setup for a character for a game and see the benefits of the items. This feature should be available for just everyone. But when the user wanna save the config he has to be logged in.
– Andreas B
Nov 21 '18 at 15:20














1 Answer
1






active

oldest

votes


















0














Use Laravel Authentication. Run this command to generate Authentication



php artisan make:auth


On your Login Controller



AppHttpControllersAuthLoginController.php


Add this Method on Login Controller



protected function authenticated(Request $request,$user){
if(auth::id()){
return redirect('/admin/dashboard');
}
return redirect('/user/dashboard');
}


On your formAction method check the user logged in or not by



  Auth::id();


if Authentication id not found then put your form data on Session and redirect user to logged in page and after logged in you can easily get the form submit data by session.






share|improve this answer























  • And how will that help me to solve my problem?
    – Andreas B
    Nov 21 '18 at 15:21










  • I have just edited my comment .
    – MD. Jubair Mizan
    Nov 21 '18 at 15:30










  • I have already implemented authentication. I asked how the form can be sent automatically after authentication. For now I can submit the form - then I will be redirected to the login (if im not logged in yet) and then I will be redirected to the form again and have to click on submit again. But I don't want the form to be sent once more.
    – Andreas B
    Nov 21 '18 at 16:20










  • If i am not getting wrong you want record a new Information while User logged in.
    – MD. Jubair Mizan
    Nov 21 '18 at 16:35






  • 1




    Let's assume it would be a comment function. Everyone can see the post. Under that post ypu have a comment input box and a submit button (save / post the comment). When you have clicked the submit button the method to store the comment will be called. But the auth middleware will check if the user is logged in. If so, the comment will be saved by the store method. If the user is not logged in, the auth middleware will redirect the user to the login page. After a successful login the comment then should be stored without having the user to write and send the comment again.
    – Andreas B
    Nov 21 '18 at 16:46













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53414842%2flaravel-form-action-after-authentication%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Use Laravel Authentication. Run this command to generate Authentication



php artisan make:auth


On your Login Controller



AppHttpControllersAuthLoginController.php


Add this Method on Login Controller



protected function authenticated(Request $request,$user){
if(auth::id()){
return redirect('/admin/dashboard');
}
return redirect('/user/dashboard');
}


On your formAction method check the user logged in or not by



  Auth::id();


if Authentication id not found then put your form data on Session and redirect user to logged in page and after logged in you can easily get the form submit data by session.






share|improve this answer























  • And how will that help me to solve my problem?
    – Andreas B
    Nov 21 '18 at 15:21










  • I have just edited my comment .
    – MD. Jubair Mizan
    Nov 21 '18 at 15:30










  • I have already implemented authentication. I asked how the form can be sent automatically after authentication. For now I can submit the form - then I will be redirected to the login (if im not logged in yet) and then I will be redirected to the form again and have to click on submit again. But I don't want the form to be sent once more.
    – Andreas B
    Nov 21 '18 at 16:20










  • If i am not getting wrong you want record a new Information while User logged in.
    – MD. Jubair Mizan
    Nov 21 '18 at 16:35






  • 1




    Let's assume it would be a comment function. Everyone can see the post. Under that post ypu have a comment input box and a submit button (save / post the comment). When you have clicked the submit button the method to store the comment will be called. But the auth middleware will check if the user is logged in. If so, the comment will be saved by the store method. If the user is not logged in, the auth middleware will redirect the user to the login page. After a successful login the comment then should be stored without having the user to write and send the comment again.
    – Andreas B
    Nov 21 '18 at 16:46


















0














Use Laravel Authentication. Run this command to generate Authentication



php artisan make:auth


On your Login Controller



AppHttpControllersAuthLoginController.php


Add this Method on Login Controller



protected function authenticated(Request $request,$user){
if(auth::id()){
return redirect('/admin/dashboard');
}
return redirect('/user/dashboard');
}


On your formAction method check the user logged in or not by



  Auth::id();


if Authentication id not found then put your form data on Session and redirect user to logged in page and after logged in you can easily get the form submit data by session.






share|improve this answer























  • And how will that help me to solve my problem?
    – Andreas B
    Nov 21 '18 at 15:21










  • I have just edited my comment .
    – MD. Jubair Mizan
    Nov 21 '18 at 15:30










  • I have already implemented authentication. I asked how the form can be sent automatically after authentication. For now I can submit the form - then I will be redirected to the login (if im not logged in yet) and then I will be redirected to the form again and have to click on submit again. But I don't want the form to be sent once more.
    – Andreas B
    Nov 21 '18 at 16:20










  • If i am not getting wrong you want record a new Information while User logged in.
    – MD. Jubair Mizan
    Nov 21 '18 at 16:35






  • 1




    Let's assume it would be a comment function. Everyone can see the post. Under that post ypu have a comment input box and a submit button (save / post the comment). When you have clicked the submit button the method to store the comment will be called. But the auth middleware will check if the user is logged in. If so, the comment will be saved by the store method. If the user is not logged in, the auth middleware will redirect the user to the login page. After a successful login the comment then should be stored without having the user to write and send the comment again.
    – Andreas B
    Nov 21 '18 at 16:46
















0












0








0






Use Laravel Authentication. Run this command to generate Authentication



php artisan make:auth


On your Login Controller



AppHttpControllersAuthLoginController.php


Add this Method on Login Controller



protected function authenticated(Request $request,$user){
if(auth::id()){
return redirect('/admin/dashboard');
}
return redirect('/user/dashboard');
}


On your formAction method check the user logged in or not by



  Auth::id();


if Authentication id not found then put your form data on Session and redirect user to logged in page and after logged in you can easily get the form submit data by session.






share|improve this answer














Use Laravel Authentication. Run this command to generate Authentication



php artisan make:auth


On your Login Controller



AppHttpControllersAuthLoginController.php


Add this Method on Login Controller



protected function authenticated(Request $request,$user){
if(auth::id()){
return redirect('/admin/dashboard');
}
return redirect('/user/dashboard');
}


On your formAction method check the user logged in or not by



  Auth::id();


if Authentication id not found then put your form data on Session and redirect user to logged in page and after logged in you can easily get the form submit data by session.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 17:59

























answered Nov 21 '18 at 15:16









MD. Jubair Mizan

606511




606511












  • And how will that help me to solve my problem?
    – Andreas B
    Nov 21 '18 at 15:21










  • I have just edited my comment .
    – MD. Jubair Mizan
    Nov 21 '18 at 15:30










  • I have already implemented authentication. I asked how the form can be sent automatically after authentication. For now I can submit the form - then I will be redirected to the login (if im not logged in yet) and then I will be redirected to the form again and have to click on submit again. But I don't want the form to be sent once more.
    – Andreas B
    Nov 21 '18 at 16:20










  • If i am not getting wrong you want record a new Information while User logged in.
    – MD. Jubair Mizan
    Nov 21 '18 at 16:35






  • 1




    Let's assume it would be a comment function. Everyone can see the post. Under that post ypu have a comment input box and a submit button (save / post the comment). When you have clicked the submit button the method to store the comment will be called. But the auth middleware will check if the user is logged in. If so, the comment will be saved by the store method. If the user is not logged in, the auth middleware will redirect the user to the login page. After a successful login the comment then should be stored without having the user to write and send the comment again.
    – Andreas B
    Nov 21 '18 at 16:46




















  • And how will that help me to solve my problem?
    – Andreas B
    Nov 21 '18 at 15:21










  • I have just edited my comment .
    – MD. Jubair Mizan
    Nov 21 '18 at 15:30










  • I have already implemented authentication. I asked how the form can be sent automatically after authentication. For now I can submit the form - then I will be redirected to the login (if im not logged in yet) and then I will be redirected to the form again and have to click on submit again. But I don't want the form to be sent once more.
    – Andreas B
    Nov 21 '18 at 16:20










  • If i am not getting wrong you want record a new Information while User logged in.
    – MD. Jubair Mizan
    Nov 21 '18 at 16:35






  • 1




    Let's assume it would be a comment function. Everyone can see the post. Under that post ypu have a comment input box and a submit button (save / post the comment). When you have clicked the submit button the method to store the comment will be called. But the auth middleware will check if the user is logged in. If so, the comment will be saved by the store method. If the user is not logged in, the auth middleware will redirect the user to the login page. After a successful login the comment then should be stored without having the user to write and send the comment again.
    – Andreas B
    Nov 21 '18 at 16:46


















And how will that help me to solve my problem?
– Andreas B
Nov 21 '18 at 15:21




And how will that help me to solve my problem?
– Andreas B
Nov 21 '18 at 15:21












I have just edited my comment .
– MD. Jubair Mizan
Nov 21 '18 at 15:30




I have just edited my comment .
– MD. Jubair Mizan
Nov 21 '18 at 15:30












I have already implemented authentication. I asked how the form can be sent automatically after authentication. For now I can submit the form - then I will be redirected to the login (if im not logged in yet) and then I will be redirected to the form again and have to click on submit again. But I don't want the form to be sent once more.
– Andreas B
Nov 21 '18 at 16:20




I have already implemented authentication. I asked how the form can be sent automatically after authentication. For now I can submit the form - then I will be redirected to the login (if im not logged in yet) and then I will be redirected to the form again and have to click on submit again. But I don't want the form to be sent once more.
– Andreas B
Nov 21 '18 at 16:20












If i am not getting wrong you want record a new Information while User logged in.
– MD. Jubair Mizan
Nov 21 '18 at 16:35




If i am not getting wrong you want record a new Information while User logged in.
– MD. Jubair Mizan
Nov 21 '18 at 16:35




1




1




Let's assume it would be a comment function. Everyone can see the post. Under that post ypu have a comment input box and a submit button (save / post the comment). When you have clicked the submit button the method to store the comment will be called. But the auth middleware will check if the user is logged in. If so, the comment will be saved by the store method. If the user is not logged in, the auth middleware will redirect the user to the login page. After a successful login the comment then should be stored without having the user to write and send the comment again.
– Andreas B
Nov 21 '18 at 16:46






Let's assume it would be a comment function. Everyone can see the post. Under that post ypu have a comment input box and a submit button (save / post the comment). When you have clicked the submit button the method to store the comment will be called. But the auth middleware will check if the user is logged in. If so, the comment will be saved by the store method. If the user is not logged in, the auth middleware will redirect the user to the login page. After a successful login the comment then should be stored without having the user to write and send the comment again.
– Andreas B
Nov 21 '18 at 16:46




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53414842%2flaravel-form-action-after-authentication%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python