资源路由返回空白页面

时间:2015-10-06 12:53:48

标签: php crud laravel-5.1

我试图在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', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@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时,我会看到一个没有内容的空白页面,我不知道为什么,请帮忙?

1 个答案:

答案 0 :(得分:0)

您的网址不应附加/ index。 Route::resource()会自动为您创建路线。尝试从命令行键入php artisan route:list,您应该获得所有应用程序路由,包括Route::resource创建的路由。

因此,在您的情况下,资源基本上正在做:

Route::get('/markers', 'MarkerController@index')

然后您将其视为:

http://yourdomain.com/markers