當我去「/ todos和/ todos/id」時,我遇到了我在laravel的路由問題,但是當我嘗試使用「/ todos/create」時,我得到了一個No查詢結果[TodoList ] 我是新來這個,請幫我...我真的不想放棄,因爲我真的很喜歡這個MVC在Laravel爲什麼我會得到模型[TodoList]的否查詢結果?
這裏是我的路線
Route::get('/', '[email protected]');
Route::get('todos', '[email protected]');
Route::get('/todos/{id}', '[email protected]');
Route::get('db', function() {
$result = DB::table('todo_lists')->where('name', 'Your List')->first();
return $result->name;
});
Route::resource('todos', 'TodoListController');
模型
<?php
class TodoList extends Eloquent {}
控制器
public function index()
{
$todo_lists = TodoList::all();
return View::make('todos.index')->with('todo_lists', $todo_lists);
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
$list = new TodoList();
$list->name = "another list";
$list->save();
return "I am here by accident";
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$list = TodoList::findOrFail($id);
return View::make('todos.show')->withList($list);
}
我的看法
@extends('layouts.main') @section('content')
<h1>All todo list</h1>
<ul>
@foreach ($todo_lists as $list)
<li>{{{ $list->name }}}</li>
@endforeach
</ul>
@stop
「新TodoList」用於創建新記錄。它是有道理的,你不能得到任何查詢模型。 – edisonthk