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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…