我试图在Laravel 5.1中创建一个资源控制器(用于CRUD)。我把它添加到app/Http/routes.php:
<?php
Route::get('/', function () {
return view('home');
});
Route::get('/home', function () {
return view('home');
});
Route::resource('markers', 'MarkerController');
Route::get('auth/login', 'AuthAuthController@getLogin');
Route::post('auth/login', 'AuthAuthController@postLogin');
Route::get('auth/logout', 'AuthAuthController@getLogout');
Route::get('auth/register', 'AuthAuthController@getRegister');
Route::post('auth/register', 'AuthAuthController@postRegister');
这是我的控制器:http://pastebin.com/mcm6kfSB
这是我的观点:
@if (Session::has('message'))
<div class="alert alert-info">{{ Session::get('message') }}</div>
@endif
<table class="table table-striped table-bordered">
<thead>
<tr>
<td>Name</td>
<td>x</td>
<td>y</td>
<td>Actions</td>
</tr>
</thead>
<tbody>
@foreach($markers as $key => $value)
<tr>
<td>{{ $value->name }}</td>
<td>{{ $value->x }}</td>
<td>{{ $value->y }}</td>
<td>
<a href="markers/index">Show</a>
<a href="markers/idnex">Edit</a>
</td>
</tr>
@endforeach
</tbody>
</table>
当我去http://partyrecycler.dev/markers/index我得到一个空白页没有内容,我不知道为什么,帮助?
你的url不应该有/index附加。Route::resource()
自动为您创建路由。试着在命令行中输入php artisan route:list
,你应该得到所有的应用程序路由,包括由Route::resource
创建的路由。
所以,在你的例子中,resource实际上是在做:
Route::get('/markers', 'MarkerController@index')
,你可以这样访问它:
http://yourdomain.com/markers