'Submitting Data, Error: Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message

<form action="upload_creation" method="post">
<div class="modal-footer">
    <button type="button" class="btn btn-link" data-dismiss="modal">Cancel</button>
    <button type="submit" class="btn btn-primary">Send</button>
</div>
</form>

this is my code for form, i want to submit a file with button

public function upload_creation(Request $request){
    $input = $request->all();
    $creation = $this->creationRepository->create($input);
    foreach($request->file('direktori_gambar') as $image)
        {
            $name=time().$image->getClientOriginalName();
            $image->move(public_path().'/public/img', $name);
            $input['pictureName']=$image->getClientOriginalName();
            $input['pictureFile']='/public/img/'.$name;
            $mediaUkm = $this->creationPictRepository->create($input);   
        }     
    return view('webgallery.desktugas')->with($this->data);

this is the controller i referred to in form Action

after i click the submit button, it came up as no message error on laravel

any idea how to fix this?



Solution 1:[1]

Which method do you use in your <form> in your template?

If the route is post() (like it is in your routes) then you also need POST as method in your form.

If you have POST as method in the <form>-Tag, look if you have a hidden-input-field called _method.

More details here https://laravel.com/docs/5.5/routing#form-method-spoofing

Solution 2:[2]

this is your route in web.php locatated in routes/ folder.

first create route in web.php

web.php

Route::post('upload-creation', 'CreationController@newCreation')->name('upload-creation');

And in form use route name to give action on file submit

<form action="{{route('upload-creation')}}" method="post">
{{ csrf_field() }}
<div class="modal-footer">
    <button type="button" class="btn btn-link" data-dismiss="modal">Cancel</button>
    <button type="submit" class="btn btn-primary">Send</button>
</div>
</form>

Solution 3:[3]

use enctype="multipart/form-data" in your form tag example:

also don't forget to add {{ csrf_field() }}

Solution 4:[4]

You need to add a hidden input to your form to include your csrf token.

Laravel 5.6, 5.7

<form action="upload_creation" method="post">
    @csrf
    <div class="modal-footer">
        <button type="button" class="btn btn-link" data-dismiss="modal">Cancel</button>
        <button type="submit" class="btn btn-primary">Send</button>
    </div>
</form>

For reference visit the Documentation.

For older versions of laravel, the syntax is slightly different:

{{ csrf_field() }}

Solution 5:[5]

you can use Form Helper using Laravel Collectives

Begin by installing this package through Composer. Run the following from the Terminal:

composer require "laravelcollective/html":"^5.2.0"

Next, add your new provider to the providers' array of config/app.php:

'providers' => [
    // ...
    Collective\Html\HtmlServiceProvider::class,
    // ...
  ],

Finally, add two class aliases to the aliases array of config/app.php:

'aliases' => [
    // ...
      'Form' => Collective\Html\FormFacade::class,
      'Html' => Collective\Html\HtmlFacade::class,
    // ...
  ],

Opening & Closing Form

{{ Form::open(['url' => route('upload-creation')]) }}

 // default method is post, you can change by adding **method** key

{{ Form::close() }}

it will automatically generate the @csrf code which will be hidden but will be available during request submission

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ismoil Shifoev
Solution 2
Solution 3 Cheran
Solution 4
Solution 5 Kishor Pant