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).