Form submit intercepted by auth middleware in laravel 5
up vote
1
down vote
favorite
I 've been working on a laravel 5.7 blog project. I want to comment an article. I need to achieve this:
Before logging in, I can type anything in comment textarea.
I submit comment(of course it would be intercepted by auth
middleware),then I'm redirected to login page,
After logging in, **I hope my app could submit previous form
data(or comment) automaticlly instead of typing the same comment again.- I think that's a very common bussiness logic in many websites nowdays,
but how am I supposed to achieve this?
My comments controller here:
public function __construct()
$this->middleware('auth');
public function store(Post $post)
$comment = Comment::create([
'body' => session('comment')?:request('body'),
'post_id' => $post->id,
'user_id' => auth()->user()->id
//before logging in, you don't have an user_id yet.
]);
return back()->with('success', 'Add comment succeeded');
web.php Route here:
Route::post('/posts/post/comments', 'CommentsController@store')->name('addComment');
Basiclly auth middleware intercepted my form data submit, I want to go across the auth middleware with my form data. Not lost them after logging in.
laravel laravel-5 laravel-middleware
add a comment |
up vote
1
down vote
favorite
I 've been working on a laravel 5.7 blog project. I want to comment an article. I need to achieve this:
Before logging in, I can type anything in comment textarea.
I submit comment(of course it would be intercepted by auth
middleware),then I'm redirected to login page,
After logging in, **I hope my app could submit previous form
data(or comment) automaticlly instead of typing the same comment again.- I think that's a very common bussiness logic in many websites nowdays,
but how am I supposed to achieve this?
My comments controller here:
public function __construct()
$this->middleware('auth');
public function store(Post $post)
$comment = Comment::create([
'body' => session('comment')?:request('body'),
'post_id' => $post->id,
'user_id' => auth()->user()->id
//before logging in, you don't have an user_id yet.
]);
return back()->with('success', 'Add comment succeeded');
web.php Route here:
Route::post('/posts/post/comments', 'CommentsController@store')->name('addComment');
Basiclly auth middleware intercepted my form data submit, I want to go across the auth middleware with my form data. Not lost them after logging in.
laravel laravel-5 laravel-middleware
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I 've been working on a laravel 5.7 blog project. I want to comment an article. I need to achieve this:
Before logging in, I can type anything in comment textarea.
I submit comment(of course it would be intercepted by auth
middleware),then I'm redirected to login page,
After logging in, **I hope my app could submit previous form
data(or comment) automaticlly instead of typing the same comment again.- I think that's a very common bussiness logic in many websites nowdays,
but how am I supposed to achieve this?
My comments controller here:
public function __construct()
$this->middleware('auth');
public function store(Post $post)
$comment = Comment::create([
'body' => session('comment')?:request('body'),
'post_id' => $post->id,
'user_id' => auth()->user()->id
//before logging in, you don't have an user_id yet.
]);
return back()->with('success', 'Add comment succeeded');
web.php Route here:
Route::post('/posts/post/comments', 'CommentsController@store')->name('addComment');
Basiclly auth middleware intercepted my form data submit, I want to go across the auth middleware with my form data. Not lost them after logging in.
laravel laravel-5 laravel-middleware
I 've been working on a laravel 5.7 blog project. I want to comment an article. I need to achieve this:
Before logging in, I can type anything in comment textarea.
I submit comment(of course it would be intercepted by auth
middleware),then I'm redirected to login page,
After logging in, **I hope my app could submit previous form
data(or comment) automaticlly instead of typing the same comment again.- I think that's a very common bussiness logic in many websites nowdays,
but how am I supposed to achieve this?
My comments controller here:
public function __construct()
$this->middleware('auth');
public function store(Post $post)
$comment = Comment::create([
'body' => session('comment')?:request('body'),
'post_id' => $post->id,
'user_id' => auth()->user()->id
//before logging in, you don't have an user_id yet.
]);
return back()->with('success', 'Add comment succeeded');
web.php Route here:
Route::post('/posts/post/comments', 'CommentsController@store')->name('addComment');
Basiclly auth middleware intercepted my form data submit, I want to go across the auth middleware with my form data. Not lost them after logging in.
laravel laravel-5 laravel-middleware
laravel laravel-5 laravel-middleware
asked Nov 11 at 15:19
Wayne lee
612
612
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
I think the solution to your problem is here:
https://laravel.com/docs/5.7/session#storing-data
You are right, and i knew it. I just don't know how until yesterday.
– Wayne lee
Nov 12 at 22:24
add a comment |
up vote
0
down vote
accepted
Here is the solution.A little tricky.Save comment to the session first before go to auth middleware.After logging in, GET that route to create comment.
Route:
Route::get('/posts/post/comments', 'CommentsController@store')->name('addComment');
Route::post('/posts/post/comments', 'CommentsController@commentSave');
Comments controller:
public function __construct()
$this->middleware('auth', ['except' => ['commentSave']]);
public function commentSave(Request $request)
$url = URL::previous();
session(['comment' => $request->input('body')]);
return redirect("$url/comments");
public function store(Post $post)
if(session('comment'))
$comment = Comment::create([
'body' => session('comment'),
'post_id' => $post->id,
'user_id' => auth()->user()->id
]);
session(['comment' => null]);
return redirect("posts/$post->id")->with('success', 'Add comment succeeded');
return redirect("posts/$post->id");
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I think the solution to your problem is here:
https://laravel.com/docs/5.7/session#storing-data
You are right, and i knew it. I just don't know how until yesterday.
– Wayne lee
Nov 12 at 22:24
add a comment |
up vote
0
down vote
I think the solution to your problem is here:
https://laravel.com/docs/5.7/session#storing-data
You are right, and i knew it. I just don't know how until yesterday.
– Wayne lee
Nov 12 at 22:24
add a comment |
up vote
0
down vote
up vote
0
down vote
I think the solution to your problem is here:
https://laravel.com/docs/5.7/session#storing-data
I think the solution to your problem is here:
https://laravel.com/docs/5.7/session#storing-data
answered Nov 11 at 17:09
Youss
304
304
You are right, and i knew it. I just don't know how until yesterday.
– Wayne lee
Nov 12 at 22:24
add a comment |
You are right, and i knew it. I just don't know how until yesterday.
– Wayne lee
Nov 12 at 22:24
You are right, and i knew it. I just don't know how until yesterday.
– Wayne lee
Nov 12 at 22:24
You are right, and i knew it. I just don't know how until yesterday.
– Wayne lee
Nov 12 at 22:24
add a comment |
up vote
0
down vote
accepted
Here is the solution.A little tricky.Save comment to the session first before go to auth middleware.After logging in, GET that route to create comment.
Route:
Route::get('/posts/post/comments', 'CommentsController@store')->name('addComment');
Route::post('/posts/post/comments', 'CommentsController@commentSave');
Comments controller:
public function __construct()
$this->middleware('auth', ['except' => ['commentSave']]);
public function commentSave(Request $request)
$url = URL::previous();
session(['comment' => $request->input('body')]);
return redirect("$url/comments");
public function store(Post $post)
if(session('comment'))
$comment = Comment::create([
'body' => session('comment'),
'post_id' => $post->id,
'user_id' => auth()->user()->id
]);
session(['comment' => null]);
return redirect("posts/$post->id")->with('success', 'Add comment succeeded');
return redirect("posts/$post->id");
add a comment |
up vote
0
down vote
accepted
Here is the solution.A little tricky.Save comment to the session first before go to auth middleware.After logging in, GET that route to create comment.
Route:
Route::get('/posts/post/comments', 'CommentsController@store')->name('addComment');
Route::post('/posts/post/comments', 'CommentsController@commentSave');
Comments controller:
public function __construct()
$this->middleware('auth', ['except' => ['commentSave']]);
public function commentSave(Request $request)
$url = URL::previous();
session(['comment' => $request->input('body')]);
return redirect("$url/comments");
public function store(Post $post)
if(session('comment'))
$comment = Comment::create([
'body' => session('comment'),
'post_id' => $post->id,
'user_id' => auth()->user()->id
]);
session(['comment' => null]);
return redirect("posts/$post->id")->with('success', 'Add comment succeeded');
return redirect("posts/$post->id");
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Here is the solution.A little tricky.Save comment to the session first before go to auth middleware.After logging in, GET that route to create comment.
Route:
Route::get('/posts/post/comments', 'CommentsController@store')->name('addComment');
Route::post('/posts/post/comments', 'CommentsController@commentSave');
Comments controller:
public function __construct()
$this->middleware('auth', ['except' => ['commentSave']]);
public function commentSave(Request $request)
$url = URL::previous();
session(['comment' => $request->input('body')]);
return redirect("$url/comments");
public function store(Post $post)
if(session('comment'))
$comment = Comment::create([
'body' => session('comment'),
'post_id' => $post->id,
'user_id' => auth()->user()->id
]);
session(['comment' => null]);
return redirect("posts/$post->id")->with('success', 'Add comment succeeded');
return redirect("posts/$post->id");
Here is the solution.A little tricky.Save comment to the session first before go to auth middleware.After logging in, GET that route to create comment.
Route:
Route::get('/posts/post/comments', 'CommentsController@store')->name('addComment');
Route::post('/posts/post/comments', 'CommentsController@commentSave');
Comments controller:
public function __construct()
$this->middleware('auth', ['except' => ['commentSave']]);
public function commentSave(Request $request)
$url = URL::previous();
session(['comment' => $request->input('body')]);
return redirect("$url/comments");
public function store(Post $post)
if(session('comment'))
$comment = Comment::create([
'body' => session('comment'),
'post_id' => $post->id,
'user_id' => auth()->user()->id
]);
session(['comment' => null]);
return redirect("posts/$post->id")->with('success', 'Add comment succeeded');
return redirect("posts/$post->id");
answered Nov 12 at 22:36
Wayne lee
612
612
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250146%2fform-submit-intercepted-by-auth-middleware-in-laravel-5%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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