duangu8264 2014-07-29 15:16
浏览 31

Laravel 4:图像控制器@ destroy返回HTTP 500

I wrote a controller in Laravel 4.2, to delete an image from the database. Every method is working so far, except for the destroy method. When I try to call the URI via cURL, I get a Laravel error page's HTML in my Terminal on Mac OS X.

<?php

class ImagesController extends \BaseController
{

    /**
     * Display a listing of the resource.
     * GET /images
     *
     * @return Response
     */
    public function index()
    {
        $images = Image::where('image_id', '>', 0)->get();

        return Response::json(array(
            'error' => false,
            'images' => $images->toArray()
        ), 200);
    }

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

    /**
     * Store a newly created resource in storage.
     * POST /images
     *
     * @return Response
     */
    public function store()
    {
        $image = new Image();
        $image->image_id = Request::get('id');
        $image->title = "Testtesttest";
        $image->alt = "Test";
        $image->filename = "Test";
        $image->filepath = "~/jbehrens";
        $image->width = 100;
        $image->height = 100;
        $image->created_at = "2014-07-28 11:00:00";
        $image->updated_at = "2014-07-29 13:00:00";
        $image->save();

        return Response::json(array(
                'error' => false,
                'images' => $image->toArray()),
            200
        );
    }

    /**
     * Display the specified resource.
     * GET /images/{id}
     *
     * @param  int $id
     * @return Response
     */
    public function show($id)
    {
        $image = Image::where('image_id', $id)
            ->take(1)
            ->get();


        return Response::json(array(
            'error' => false,
            'image' => $image->toArray()
        ), 200);
    }

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

    }

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

    /**
     * Remove the specified resource from storage.
     * DELETE /images/{id}
     *
     * @param  int $id
     * @return Response
     */
    public function destroy($id)
    {
        $image = Image::where('media_id', '>', 0)->find($id);
        $image->delete();

        return Response::json(array(
                'error' => false,
                'message' => 'url deleted'),
            200
        );
    }

}

The command I am issuing is the following curl -i -X DELETE http://link/portfolio/public/images/3 (example given).

  • 写回答

2条回答 默认 最新

  • droe9376 2014-07-29 15:20
    关注

    Replace this:

    $image = Image::where('media_id', '>', 0)->find($id);
    

    with this:

    $image = Image::find($id);
    

    in yourdestroy function.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?