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.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire