简体   繁体   中英

Laravel - Allowing Authenticated and Non Authenticated users to post

I'm wondering if someone could shed some light on an issue im having.

I am following a tutorial on Laracasts about building a forum using Laravel ( 5.4 ) and TDD.

At the moment we have developed the authentication system and now its moving on to actually posting a 'thread'.

In the tutorial, only logged in users can post, then the post is associated with the user that posted it.

But, how would i go about allowing non-logged in users to post as well.

What would be the best approach to take to this?

Any help would be greatly appreciated.

Solution, maybe not good : Create anonymous user in your users table (with ID = 0 for example). And after if user is not logged in to post a thread, you use anonymous user, and you store IP address in your thread table.

Storing IP Address will permit you to attribute thread when user will decide to create his account (and replace 0 by the real user_id in the futur)

Laravel Provides an authentication which can be injected in the constructor of your controller .

Check this link for your reference https://laravel.com/docs/5.4/authentication

or Since your watching Laracast what the Laravel from Scratch the part where jeffrey is creating a Blog

Good Luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM