Home > other >  The POST method is not supported for this route. Supported methods: GET, HEAD, PUT, PATCH, DELETE. L
The POST method is not supported for this route. Supported methods: GET, HEAD, PUT, PATCH, DELETE. L

Time:05-14

hello i have a problem with uploading a form this is my form

@extends('layouts.app-admin')
@section('content')
    <div >
        <div >
            <div >
                <h1>Subir Accesorio</h1>
                <div >
                    <div >
                        <form action="{{ 'admin.files.store' }}" method="POST" enctype="multipart/form-data">

                        @csrf

                        <div >
                            <label for="nombre"
                                >{{ __('Nombre Producto') }}</label>
                            <input type="text" name="nombre">
                        </div>

                        <div >
                            <label for="precio"
                                >{{ __('Precio Producto') }}</label>
                            <input type="number" name="precioUnitario">
                        </div>
                        <div >
                            <label for="stock"
                                >{{ __('Stock Producto') }}</label>
                            <input type="number" name="stock">
                        </div>

                        <div >
                            <label for="descripcion"
                                >{{ __('Descripcion Producto') }}</label>
                            <input type="text" name="descripcion">
                        </div>

                        <div >
                            <label for="usuario"
                                >{{ __('Imagen Producto') }}</label>
                            <input type="file" name="imagen" id="">
                        </div>

                        <div >
                            <button type="submit" >Subir Productos</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

my web.php is

Route::resource('/admin/files', FileController::class)->names('admin.files');

and controller

<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\File;

class FileController extends Controller
{
    /**
 * Display a listing of the resource.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{
    return view('admin.files.index');
}

/**
 * Show the form for creating a new resource.
 *
 * @return \Illuminate\Http\Response
 */
public function create()
{
    return view('admin.files.create');
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(Request $request)
{
    return $request->all();
}

/**
 * Display the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function show($file)
{
    return view('admin.files.show');
}

/**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function edit($file)
{
    return view('admin.files.edit');
}

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function update(Request $request, $file)
{
    //
}

/**
 * Remove the specified resource from storage.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function destroy($file)
{
    //
}
}

and if I use the r command r:l

GET|HEAD        admin ...................... admin.principal › Admin\PrincipalController@principal 
  GET|HEAD        admin/files ....................... admin.files.index › Admin\FileController@index 
  POST            admin/files ....................... admin.files.store › Admin\FileController@store 
  GET|HEAD        admin/files/create .............. admin.files.create › Admin\FileController@create 
  GET|HEAD        admin/files/{file} .................. admin.files.show › Admin\FileController@show 
  PUT|PATCH       admin/files/{file} .............. admin.files.update › Admin\FileController@update  
  DELETE          admin/files/{file} ............ admin.files.destroy › Admin\FileController@destroy  
  GET|HEAD        admin/files/{file}/edit ............. admin.files.edit › Admin\FileController@edit  

the problem is that the method POST is not supported but it is that in the route it uses POST and I don't know what to do I try several things but I can't find a solution and I don't advance my goal is to upload a product through a form

CodePudding user response:

Forgot to add route function on action attribute

<form action="{{ route('admin.files.store') }}" method="POST" enctype="multipart/form-data">

CodePudding user response:

I had a smillier error ..try to check the following

  1. the action name should be the same of route name :

action="{{ route('admin.files.store')}}

2)check that you are using get to return the view of form and then post when you send request

CodePudding user response:

Have had a similar problem. This is what I did try running this command

php artisan route:clear

  • Related