在Laravel中为我的资源控制器添加GET输入


Adding GET input to my resourceful controller in Laravel

使用Laravel 4创建一个"Read-it-Later"应用程序,只是为了测试目的。我能够使用以下curl命令成功地将URL和Description存储到我的应用程序中:

curl -d 'url=http://testsite.com&description=For Testing' readitlater.local/api/v1/url

我有兴趣使用GET来完成同样的事情,但通过传递我的变量在一个URL(例如readitlater.local/api/v1/URL ? URL =testsite.com?description=For%20Testing)

这是我的UrlController段:

/**
 * Store a newly created resource in storage.
 *
 * @return Response
 */
public function store()
{
    $url = new Url;
    $url->url = Request::get('url');
    $url->description = Request::get('description');
    $url->save();
    return Response::json(array(
        'error' => false,
        'urls' => $urls->toArray()),
        200
    );
}

这是我的Url模型:

<?php
class Url extends Eloquent {
    protected $table = 'urls';
}

我阅读了关于输入类型的Laravel文档,但我不确定如何将其应用于我当前的控制器:http://laravel.com/docs/requests#basic-input

提示吗?

您没有应用正确链接到…使用Input::get()从GET或POST获取任何内容,使用Request类获取有关当前请求的信息。你在找这样的东西吗?

        public function store()
        {
            $url = new Url; // I guess this is your Model
            $url->url = Request::url();
            $url->description = Input::get('description');
            $url->save();
            return Response::json(array(
                'error' => false,
                'urls' => Url::find($url->id)->toArray(), 
    /* Not sure about this. You want info for the current url? 
    (you already have them...no need to query the DB) or you want ALL the urls? 
    In this case, use Url::all()->toArray()
    */
                200
            );
        }