【问题标题】:Laravel RESTful Controller Redirects on POST onlyLaravel RESTful 控制器仅在 POST 上重定向
【发布时间】:2015-02-08 19:54:52
【问题描述】:

我创建了一个 RESTful 控制器。当我尝试创建新资源 (POST) 时,它会将我重定向到 404。

/app-container/public/index.php/api/v1 ->

/index.php/api/v1 ->

/api/v1 -> 404

这是我的控制器路线:

Route::resource('restauranthours', 'restaurantHoursController');

这是我的控制器:

class restaurantHoursController extends \BaseController {

/**
 * Display a listing of the resource.
 *
 * @return Response
 */
public function index()
{
    //
}


/**
 * Show the form for creating a new resource.
 *
 * @return Response
 */
public function create()
{
    //
    return "Create";
}


/**
 * Store a newly created resource in storage.
 *
 * @return Response
 */
public function store()
{
    //
    return "Store";
}


/**
 * Display the specified resource.
 *
 * @param  int  $id
 * @return Response
 */
public function show($id)
{
    //
    $day = $_GET['day'];
    return Response::json(DB::select('select * from restaurantHours where restId=? and day=? order by day',array($id, $day)));
}


/**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return Response
 */
public function edit($id)
{
    //
}


/**
 * Update the specified resource in storage.
 *
 * @param  int  $id
 * @return Response
 */
public function update($id)
{
    //
    return "Update";
}


/**
 * Remove the specified resource from storage.
 *
 * @param  int  $id
 * @return Response
 */
public function destroy($id)
{
    //
} }

如果我使用 GET 或 PUT,它会给我显示的值。它只在 POST 上重定向。

【问题讨论】:

    标签: php rest laravel


    【解决方案1】:

    PUT 不会创建新资源;它更新现有资源。 POST 创建一个新资源。

    【讨论】:

    • 是的,我的意思是写“POST”。它在 POST 到 url 时重定向。我已经编辑了问题。
    猜你喜欢
    • 2013-08-26
    • 2013-11-30
    • 1970-01-01
    • 2013-12-31
    • 1970-01-01
    • 1970-01-01
    • 2017-04-26
    • 2014-01-24
    • 2013-10-12
    相关资源
    最近更新 更多