I tried an experiment earlier by allowing an admin user to replace an image that was already uploaded to the database. As a test, I allowed for submission of a 'blank' or 'empty' photo to be uploaded. After the 'blank' photo was uploaded, I then tried to delete it but I keep getting a 'Trying to get property of non-object' error.
Controller:
public function destroy($albumId, $photoId)
{
$this->photo->delete($photoId);
return \Redirect::route("gallery.album.show", array('id' => $albumId));
}
EDIT:
routes.php:
Route::delete('gallery/album/{albumid}/photo/{photoid}/edit', array('as'=>'delete_photo', 'uses'=>'EditPhotosController@destroy'));
View:
/*
Form code in here
*/
{{ link_to_route('delete_photo', 'Delete Photo') }}
The problem was originally that my application was looking for the original 'file path' name to delete the original photo but now that the 'file path' name is currently null, it can't match on that name and therefore won't delete it.
EDIT: I'm thinking this might actually be a routing issue.
Is there a simple solution to this problem?
There are a few problems with this.
First, you're creating a route with an HTTP DELETE
method. Links on their own make GET
requests, not DELETE
requests.
Usually you'll use a bit of javascript to submit a hidden form with a _method
param set to DELETE
to the URL in the href
of the clicked link. jquery-ujs contains this funcitonality, but you can do it with much less code.
The next problem is you're not specifying the albumid
or photoid
params on the link
{{ link_to_route('delete_photo', 'Delete Photo', [ 'albumid' => $album->id, 'photoid' => $photo->id ]) }}
Finally, a route such as
DELETE /gallery/album/{albumid}/photo/{photoid}/edit
isn't the most RESTful. The DELETE
should be made against the resource
DELETE /gallery/album/{albumid}/photo/{photoid}
Fixing the route params may fix your issue, but right now you have too much wrong and haven't provided a detailed error to give you more specifics.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments