Laravel休息路径


Laravel rest path

我有这个route.php文件:

Route::group(array('prefix' => 'api'), function () {
    Route::resource(
        'login', 'TokenController',
        ['only' => ['index', 'create', 'store', 'destroy']]
    );
});

php artisen routes输出:

+--------+---------------------------+-------------------+-------------------------+----------------+---------------+
| Domain | URI                       | Name              | Action                  | Before Filters | After Filters |
+--------+---------------------------+-------------------+-------------------------+----------------+---------------+
|        | GET|HEAD /                |                   | Closure                 |                |               |
|        | GET|HEAD api/login        | api.login.index   | TokenController@index   |                |               |
|        | GET|HEAD api/login/create | api.login.create  | TokenController@create  |                |               |
|        | POST api/login            | api.login.store   | TokenController@store   |                |               |
|        | DELETE api/login/{login}  | api.login.destroy | TokenController@destroy |                |               |
+--------+---------------------------+-------------------+-------------------------+----------------+---------------+

我需要放置什么路径才能获得TokenController响应?
我试过了:

`http://localhost/bets/api/login/create?email=vlio20%40gmail.com&password=vlad1q`

给予Error 404

我也试过了:

http://localhost/bets/api/login/create?email=vlio20%40gmail.com&password=vlad1q

显示一个空页面(响应代码是my index.php(这是一个空的HTML页面)。

注1
我使用xampp作为我的Web服务器,betts是包含文件夹。

注2
我已经将view.php配置为查找公共文件夹中的视图:

'paths' => array(__DIR__.'/../../public')

注意3

使用curl
curl -i -H "Accept: application/json" -H "Content-Type: applicatio
n/json" -X GET http://localhost/bets/public/index.php/api/login/create?email=vli
o20@gmail.com&password=vlad1q
返回:

HTTP/1.1 200 OK
Date: Fri, 06 Jun 2014 08:56:58 GMT
Server: Apache/2.4.7 (Win32) OpenSSL/0.9.8y PHP/5.4.22
X-Powered-By: PHP/5.4.22
Content-Length: 723
Content-Type: text/html
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css">
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/angular-route/angular-route.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="js/controllers/loginController.js"></script>
<script src="js/services/loginService.js"></script>
<script src="js/controllers/AppController.js"></script>
<head>
    <title>Bets Application</title>
</head>
<body ng-app="betsApp" ng-controller="appCtrl">
<div class="container">
    <div ng-view></div>
</div>
</body>
</html>'password' is not recognized as an internal or external command,
operable program or batch file.

实际上答案是php artisen routes命令的结果:

  1. 如果您使用GET请求方法(从浏览器地址栏或单击链接)使用http://localhost/bets/api/login请求,那么它将击中index方法。
  2. 如果你使用http://localhost/bets/api/login/createGET请求方法(从浏览器地址栏或点击链接)发出请求,那么它将击中create方法。
  3. 如果您使用http://localhost/bets/api/loginPOST请求方法(使用formaction='http://localhost/bets/api/login')发出请求,那么它将击中store方法。

  4. 如果你使用http://localhost/bets/api/login/idPOST请求方法(使用form,其中action='http://localhost/bets/api/login/1')发出请求,那么它将击中delete方法。1可以是任何id,如120等,但也需要为DELETE方法添加隐藏输入,如:

要生成表单,您应该使用如下命令:

Form::open(array('route' => array('api.login.destroy', 1), 'method' => 'delete'))

注意1它应该是你想要删除的模型的id它基本上可以是类似$modelInstance->id的东西因为你可能会从你的控制器传递一个模型到你将生成这个表单的视图。查看更多Laravel文档

经过长时间的调查,我从零开始!现在我把我的主php文件(app.php)放在app/view目录下,所有的js, css等文件放在公共目录下。我还将laravel视图路径更改为默认路径(app/views),并将app/route.php文件更改为:

<?php
Route::get('/', function()
{
    return View::make('app');
});
Route::group(array('prefix' => 'api'), function()
{
    Route::resource('login', 'TokenController',
        array('only' => array('index', 'create', 'store', 'destroy')));
});
App::missing(function($exception)
{
    return View::make('index');
});

希望对你有帮助!