Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

php - 不允许使用的方法-Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException不支持POST方法(Method not alowed - SymfonyComponentHttpKernelExceptionMethodNotAllowedHttpException The POST method is not supported)

I am trying to do a course in Laravel and I try to set up a simple CRUD method and I got stuck on the Create.

(我试图在Laravel中学习一门课程,并且尝试设置一个简单的CRUD方法,但被卡在Create上。)

I have an error in Laravel and I do not understand how to solve it, I tried to clear route-cache but does not work.

(我在Laravel中有一个错误,我不明白如何解决,我试图清除路由缓存,但是不起作用。)

I watched some answers with this error but i am not sure do they match as I am using the post method in web file.

(我看到了一些与此错误有关的答案,但我不确定它们是否匹配,因为我在Web文件中使用post方法。)

Snippet

(片段)

Controller

(控制者)

namespace AppHttpControllers;

use AppTodo;

use IlluminateHttpRequest;

class TodosControler extends Controller
{





public function index() 
{
    return view('todos.index')->with('todos', Todo::all());
}

//za pojedine 
public function show($todoId)
{
    //dd($todoId); //diedump isto kao die u PHPu

     // $todo = Todo::find($todoId);  onda ovo kad slozimo samo stavimo u return
     return view('todos.show')->with('todo', Todo::find($todoId));
}

public function create()
{
    return view('todos.create');
}

public function store()
{
  $data = request()->all();
  $todo = new Todo();
  $todo->name = $data['name'];
  $todo->description = $data['description'];
  $todo->completed = false;
  $todo->save();
  return redirect('/todos');
}


}

web file

(网络文件)

use AppHttpControllersAboutController;
use IlluminateSupportFacadesRoute;

Route::get('/', function () {
    return view('welcome');
});

Route::get('todos' , 'TodosControler@index');

Route::get('todos/{todo}' , 'TodosControler@show');

Route::get('new-todos' , 'TodosControler@create');

Route::post('store-todos' , 'TodosControler@store');

Form

(形成)

    <form action="/store-todos" method="POST">
             @csrf
      <div class="form-group">
           <input type="text" class="form-control" name="name" placeholder="Name">
      </div>

      <div class="form-group">
            <textarea name="description" cols="5" rows="5" class="form-control" placeholder="description"></textarea>
      </div>

      <div class="form-group text-center">
             <button type="submit" class="btn btn-success">Create todo</button>
      </div>


  </form>
  ask by Zoran Reli? translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think here is mistake Route::get('new-todos' , 'TodosControler@create') .

(我认为这是错误的Route::get('new-todos' , 'TodosControler@create') 。)

Maybe you need Route::post('new-todos' , 'TodosControler@create')

(也许您需要Route::post('new-todos' , 'TodosControler@create'))

Hope it's help.

(希望对您有所帮助。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...