Home > Mobile >  Is it necessary to use the form to transfer data to the server?
Is it necessary to use the form to transfer data to the server?

Time:04-11

I'm new to backend programming. I chose the laravel framework. Already learned the basics. During the study, the question arose: is it necessary to use the form to transfer data to the server ?. For example: the deletion route looks like this to me

<a href="{{route('admin.complaints.delete', $complaint->id)}}">Delete</a>.

If I leave it, will it be a mistake? Maybe advise an article or something. Thanks in advance

CodePudding user response:

Short answer is no, it's not necessary, but you should (if you're bound to HTML only).

The HTTP standard has different methods for different purposes. Using an anchor tag will always make a HTTP GET request to the link/server, which is not ideal, GET request should never change the remote (server) state, that's a job other methods (POST, PUT, DELETE, PATCH), you should try to use the method that better describe what you're trying to do: in your case I suppose you're trying to delete a complaint, so a DELETE or POST is what you're looking for.

The only way to use make a non GET request in plain HTML* is to use <form>. Also if you're planning to use a method different from POST you should take a look at Laravel's @method here

  • Mind that if you can and want to use JavaScript to perform your request you totally can, dropping the requirement to have use form (docs and docs).
  • Related