Shane
Shane

Reputation: 1230

Using Laravel requests for GET methods?

I've only used Laravel's Requests for POST methods. In the documentation, all examples use POST methods, but the class does offer a method to check which HTTP verb is used.

Is it advisable to use a Request when the method is GET if there is a need to validate a query, path, or authorize a user? If I were to use requests for GET methods (specifically to authorize a user), what would be the point of using auth middleware?

Upvotes: 0

Views: 718

Answers (2)

prateekkathal
prateekkathal

Reputation: 3572

I believe you are mixing 2 different terminologies together.

First of all, you must not use GET method to authorize anyone. That is totally against the law... (Unless you really want to tamper your user's privacy etc.)

Secondly, Using POST and GET methods is simply your decision. For purposes like, Authenticating users, or say making payments etc, you must make a POST request, but for purposes like Search, Pagination or Verification By Token... GET method must be preferred.

Using Laravel's Route method, you can pass as many parameters as you want to a function and not use GET method at all.

To simply put this, using either is totally your call.

Lastly, Auth Middleware is used for checking if the user who is accessing that page has a session active or not. If you login someone, you call the Laravel's auth()->login() method, which makes a session for that particular user and you can thereby get that user's info on any other view/method by auth()->user() as long as he/she is logged in. If you want, you can make your own middleware and check from the GET requests if the user's email and password are valid or not, you can do that well. But then again, like I said, this shouldn't be happening... Let's not mix up things.

I hope I have made your concepts clear and answered your question correctly. Since you've not really explained using examples, I feel this is where you were really getting confused. Please comment if you have any further doubts. :)

Upvotes: 1

Thao Ha
Thao Ha

Reputation: 1

If you want to check the permission at your GET request you can use middleware at routes.

You can create many middleware as you want

Example:

Route::get('admin/profile', function () { // })->middleware('auth');

Upvotes: 0

Related Questions