Home > Mobile >  how can I use plain html forms <form action ="" method=""> in Laravel inst
how can I use plain html forms <form action ="" method=""> in Laravel inst

Time:12-17

I'm trying to use plain HTML in Laravel but I seem to have a route problem and for being new to programming trying to figure it out seems impossible,

I'm getting this ERROS The POST method is not supported for this route. Supported methods: GET, HEAD, PUT, PATCH, DELETE. http://127.0.0.1:8000/posts/posts

Dev tools Console POST http://127.0.0.1:8000/posts/posts 405 (Method Not Allowed)

here is my code that someone showed me but still not working...

#create.blade#

form action = {{route('enter code here')}} method="POST"

    @csrf
    <div >
         <label for="title">Title</label>
         <input type="text" >
    </div>

   <div >
        <label for="body">Body</label>
        <input  rows="5" id="comment">  </input>
        <button type = "submit">Submit</button>
  </div>

</form>

I'm not sure if you can even use normal HTML with Laravel/ not sure how one would start to route them correctly

CodePudding user response:

You have to provide http method type and a valid csdrf field. Example assuming your route is defined as 'put' in your api.php/admin.php file.

<form method="POST" action="{{ route('your-route-name') }}"  enctype="multipart/form-data">

            {{ csrf_field() }}
            {{ method_field('PUT')}}

Alternatively, you can use the newer laravel convention

<form action="/foo/bar" method="POST">
    @method('PUT')

    ...
</form>

More at the docs: Method field

By the way, try not to use blade form directives such as Form::open, they are mostly deprecated AFAIK.

CodePudding user response:

You can easily use any html form in the section you've to just add the form as below that I have added

<form action="{{ route('controllername/functionname') }}"  method="POST or GET" > 
         any contents inside your form.
</form>

I hope this solves your issue.

CodePudding user response:

If you use ResourceController, you can use this.

<form action="{{ route('enter code here') }}" method="POST">
                            @csrf
                            @method('PUT')

If you use Controller (simple), you can use this.

<form action="{{ route('enter code here') }}" method="POST">
                            @csrf
  • Related