Laravel | Delete function - how to delete photo from calendar's event
How can I remove photo from calendar's event in edit calendar's event view? In list of events I did delete method and it works. Now when I try to do the same in edit.blade.php it gives error:
Call to a member function photos() on null
I have two tables in relationship one calendar to many photos, file upload works, but I stucked on edit part.
Look at my controller function:
public function deletePhoto(CalendarRepository $calRepo, $id)
{
$calendars = $calRepo->find($id);
$calendars->photos($id)->delete();
return redirect()->action('CalendarController@edit');
}
and here is fragment of edit.blade.php:
<div class="form-group">
<label for="photo">Photo:</label>
<div class="row">
@foreach(($calendar->photos) as $photo)
<div class="col-md-3">
<div class="admin-thumbnail">
<img class="img-responsive" src="/storage/{{ $photo->filename }}" style="width:100px; height:auto;"/>
</div>
<a href="{{ URL::to('calendar/deletePhoto/' . $photo->id ) }}" onClick="return confirm('Are you sure?')"><i class="fas fa-times"></i>Remove</a>
</div>
@endforeach
</div>
</div>
I need to remove photo from Photo table and redirect to edit.blade.php (about the specific event id of the calendar)
Thanks for any help.
EDIT:
<div class="card-body">
<form action="{{ action ('CalendarController@editStore')}}" method="POST" enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{csrf_token() }}"/>
<input type="hidden" name="id" value="{{ $calendar->id }}"/>
<input type="hidden" name="_token" value="{{csrf_token() }}"/>
<div class="form-group">
<label for="photo">Photo:</label>
<div class="row">
@foreach(($calendar->photos) as $photo)
<div class="col-md-3">
<div class="admin-thumbnail">
<img class="img-responsive" src="/storage/{{ $photo->filename }}"/>
</div>
<form method="POST" action="{{ route('photo.delete', ['calendar' => $calendar, 'photo' => $photo]) }}">
@csrf
@method("DELETE")
<a onClick="return confirm('Are you sure?')"><i class="fas fa-times"></i>Remove</a>
</form>
</div>
@endforeach
</div>
</div>
<div class="form-group">
<label for="header">Header</label>
<input type="text" class="form-control" name="header" value="{{ $calendar->header }}"/>
</div>
<div class="form-group">
<label for="description">Description</label>
<input type="text" class="form-control" name="description" value="{{ $calendar->description }}"/>
</div>
<div class="form-group">
<label for="date">Date</label>
<input type="date" class="form-control" name="date" value="{{ $calendar->date }}"/>
</div>
<input type="submit" value="Save" class="btn btn-primary"/>
</form>
</div>
laravel
add a comment |
How can I remove photo from calendar's event in edit calendar's event view? In list of events I did delete method and it works. Now when I try to do the same in edit.blade.php it gives error:
Call to a member function photos() on null
I have two tables in relationship one calendar to many photos, file upload works, but I stucked on edit part.
Look at my controller function:
public function deletePhoto(CalendarRepository $calRepo, $id)
{
$calendars = $calRepo->find($id);
$calendars->photos($id)->delete();
return redirect()->action('CalendarController@edit');
}
and here is fragment of edit.blade.php:
<div class="form-group">
<label for="photo">Photo:</label>
<div class="row">
@foreach(($calendar->photos) as $photo)
<div class="col-md-3">
<div class="admin-thumbnail">
<img class="img-responsive" src="/storage/{{ $photo->filename }}" style="width:100px; height:auto;"/>
</div>
<a href="{{ URL::to('calendar/deletePhoto/' . $photo->id ) }}" onClick="return confirm('Are you sure?')"><i class="fas fa-times"></i>Remove</a>
</div>
@endforeach
</div>
</div>
I need to remove photo from Photo table and redirect to edit.blade.php (about the specific event id of the calendar)
Thanks for any help.
EDIT:
<div class="card-body">
<form action="{{ action ('CalendarController@editStore')}}" method="POST" enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{csrf_token() }}"/>
<input type="hidden" name="id" value="{{ $calendar->id }}"/>
<input type="hidden" name="_token" value="{{csrf_token() }}"/>
<div class="form-group">
<label for="photo">Photo:</label>
<div class="row">
@foreach(($calendar->photos) as $photo)
<div class="col-md-3">
<div class="admin-thumbnail">
<img class="img-responsive" src="/storage/{{ $photo->filename }}"/>
</div>
<form method="POST" action="{{ route('photo.delete', ['calendar' => $calendar, 'photo' => $photo]) }}">
@csrf
@method("DELETE")
<a onClick="return confirm('Are you sure?')"><i class="fas fa-times"></i>Remove</a>
</form>
</div>
@endforeach
</div>
</div>
<div class="form-group">
<label for="header">Header</label>
<input type="text" class="form-control" name="header" value="{{ $calendar->header }}"/>
</div>
<div class="form-group">
<label for="description">Description</label>
<input type="text" class="form-control" name="description" value="{{ $calendar->description }}"/>
</div>
<div class="form-group">
<label for="date">Date</label>
<input type="date" class="form-control" name="date" value="{{ $calendar->date }}"/>
</div>
<input type="submit" value="Save" class="btn btn-primary"/>
</form>
</div>
laravel
The error you're seeing suggests that$calRepo->find($id);
isn't finding aCalendar
and is returningnull
. When you're then doing$calendar->photos(...)
you're calling a method onnull
which doesn't make sense. Does the ID in this case definitely refer to an actual calendar in your database?
– Jonathon
Nov 25 '18 at 19:28
Also, in your template it looks like you're passing the ID of the photo but in your controller you're expecting$id
to be the ID of the calendar which could explain what's going wrong
– Jonathon
Nov 25 '18 at 19:30
add a comment |
How can I remove photo from calendar's event in edit calendar's event view? In list of events I did delete method and it works. Now when I try to do the same in edit.blade.php it gives error:
Call to a member function photos() on null
I have two tables in relationship one calendar to many photos, file upload works, but I stucked on edit part.
Look at my controller function:
public function deletePhoto(CalendarRepository $calRepo, $id)
{
$calendars = $calRepo->find($id);
$calendars->photos($id)->delete();
return redirect()->action('CalendarController@edit');
}
and here is fragment of edit.blade.php:
<div class="form-group">
<label for="photo">Photo:</label>
<div class="row">
@foreach(($calendar->photos) as $photo)
<div class="col-md-3">
<div class="admin-thumbnail">
<img class="img-responsive" src="/storage/{{ $photo->filename }}" style="width:100px; height:auto;"/>
</div>
<a href="{{ URL::to('calendar/deletePhoto/' . $photo->id ) }}" onClick="return confirm('Are you sure?')"><i class="fas fa-times"></i>Remove</a>
</div>
@endforeach
</div>
</div>
I need to remove photo from Photo table and redirect to edit.blade.php (about the specific event id of the calendar)
Thanks for any help.
EDIT:
<div class="card-body">
<form action="{{ action ('CalendarController@editStore')}}" method="POST" enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{csrf_token() }}"/>
<input type="hidden" name="id" value="{{ $calendar->id }}"/>
<input type="hidden" name="_token" value="{{csrf_token() }}"/>
<div class="form-group">
<label for="photo">Photo:</label>
<div class="row">
@foreach(($calendar->photos) as $photo)
<div class="col-md-3">
<div class="admin-thumbnail">
<img class="img-responsive" src="/storage/{{ $photo->filename }}"/>
</div>
<form method="POST" action="{{ route('photo.delete', ['calendar' => $calendar, 'photo' => $photo]) }}">
@csrf
@method("DELETE")
<a onClick="return confirm('Are you sure?')"><i class="fas fa-times"></i>Remove</a>
</form>
</div>
@endforeach
</div>
</div>
<div class="form-group">
<label for="header">Header</label>
<input type="text" class="form-control" name="header" value="{{ $calendar->header }}"/>
</div>
<div class="form-group">
<label for="description">Description</label>
<input type="text" class="form-control" name="description" value="{{ $calendar->description }}"/>
</div>
<div class="form-group">
<label for="date">Date</label>
<input type="date" class="form-control" name="date" value="{{ $calendar->date }}"/>
</div>
<input type="submit" value="Save" class="btn btn-primary"/>
</form>
</div>
laravel
How can I remove photo from calendar's event in edit calendar's event view? In list of events I did delete method and it works. Now when I try to do the same in edit.blade.php it gives error:
Call to a member function photos() on null
I have two tables in relationship one calendar to many photos, file upload works, but I stucked on edit part.
Look at my controller function:
public function deletePhoto(CalendarRepository $calRepo, $id)
{
$calendars = $calRepo->find($id);
$calendars->photos($id)->delete();
return redirect()->action('CalendarController@edit');
}
and here is fragment of edit.blade.php:
<div class="form-group">
<label for="photo">Photo:</label>
<div class="row">
@foreach(($calendar->photos) as $photo)
<div class="col-md-3">
<div class="admin-thumbnail">
<img class="img-responsive" src="/storage/{{ $photo->filename }}" style="width:100px; height:auto;"/>
</div>
<a href="{{ URL::to('calendar/deletePhoto/' . $photo->id ) }}" onClick="return confirm('Are you sure?')"><i class="fas fa-times"></i>Remove</a>
</div>
@endforeach
</div>
</div>
I need to remove photo from Photo table and redirect to edit.blade.php (about the specific event id of the calendar)
Thanks for any help.
EDIT:
<div class="card-body">
<form action="{{ action ('CalendarController@editStore')}}" method="POST" enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{csrf_token() }}"/>
<input type="hidden" name="id" value="{{ $calendar->id }}"/>
<input type="hidden" name="_token" value="{{csrf_token() }}"/>
<div class="form-group">
<label for="photo">Photo:</label>
<div class="row">
@foreach(($calendar->photos) as $photo)
<div class="col-md-3">
<div class="admin-thumbnail">
<img class="img-responsive" src="/storage/{{ $photo->filename }}"/>
</div>
<form method="POST" action="{{ route('photo.delete', ['calendar' => $calendar, 'photo' => $photo]) }}">
@csrf
@method("DELETE")
<a onClick="return confirm('Are you sure?')"><i class="fas fa-times"></i>Remove</a>
</form>
</div>
@endforeach
</div>
</div>
<div class="form-group">
<label for="header">Header</label>
<input type="text" class="form-control" name="header" value="{{ $calendar->header }}"/>
</div>
<div class="form-group">
<label for="description">Description</label>
<input type="text" class="form-control" name="description" value="{{ $calendar->description }}"/>
</div>
<div class="form-group">
<label for="date">Date</label>
<input type="date" class="form-control" name="date" value="{{ $calendar->date }}"/>
</div>
<input type="submit" value="Save" class="btn btn-primary"/>
</form>
</div>
laravel
laravel
edited Nov 25 '18 at 20:15
Giacomo
asked Nov 25 '18 at 19:01
GiacomoGiacomo
104215
104215
The error you're seeing suggests that$calRepo->find($id);
isn't finding aCalendar
and is returningnull
. When you're then doing$calendar->photos(...)
you're calling a method onnull
which doesn't make sense. Does the ID in this case definitely refer to an actual calendar in your database?
– Jonathon
Nov 25 '18 at 19:28
Also, in your template it looks like you're passing the ID of the photo but in your controller you're expecting$id
to be the ID of the calendar which could explain what's going wrong
– Jonathon
Nov 25 '18 at 19:30
add a comment |
The error you're seeing suggests that$calRepo->find($id);
isn't finding aCalendar
and is returningnull
. When you're then doing$calendar->photos(...)
you're calling a method onnull
which doesn't make sense. Does the ID in this case definitely refer to an actual calendar in your database?
– Jonathon
Nov 25 '18 at 19:28
Also, in your template it looks like you're passing the ID of the photo but in your controller you're expecting$id
to be the ID of the calendar which could explain what's going wrong
– Jonathon
Nov 25 '18 at 19:30
The error you're seeing suggests that
$calRepo->find($id);
isn't finding a Calendar
and is returning null
. When you're then doing $calendar->photos(...)
you're calling a method on null
which doesn't make sense. Does the ID in this case definitely refer to an actual calendar in your database?– Jonathon
Nov 25 '18 at 19:28
The error you're seeing suggests that
$calRepo->find($id);
isn't finding a Calendar
and is returning null
. When you're then doing $calendar->photos(...)
you're calling a method on null
which doesn't make sense. Does the ID in this case definitely refer to an actual calendar in your database?– Jonathon
Nov 25 '18 at 19:28
Also, in your template it looks like you're passing the ID of the photo but in your controller you're expecting
$id
to be the ID of the calendar which could explain what's going wrong– Jonathon
Nov 25 '18 at 19:30
Also, in your template it looks like you're passing the ID of the photo but in your controller you're expecting
$id
to be the ID of the calendar which could explain what's going wrong– Jonathon
Nov 25 '18 at 19:30
add a comment |
1 Answer
1
active
oldest
votes
You use the same $id
to find the photo and the calendar instance.
GET request is not recommended for deleting a resource, so a better approach would be in your routes you can have something like this:
Route::delete('photo/{photo}', 'PhotosController@delete')->name('photo.delete');
Then in your view, you should surround the button with a Form, for example:
<form method="POST" action="{{ route('photo.delete', $photo) }}">
@csrf
@method("DELETE")
<a onClick="return confirm('Are you sure?')"><i class="fas fa-times"></i>Remove</a>
</form>
Then your confirm
function in JS should submit the form if the user accepts to delete the photo. And also remember to return false as default in the confirm function so it does not submits the form by default.
Your controller will then be:
public function delete(Photo $photo)
{
$photo->delete();
return redirect()->back();
}
--- EDIT
Route::delete('calendar/{calendar}/photo/{photo}', 'CalendarController@deletePhoto')->name('photo.delete');
and the action in the form can be:
{{ route('photo.delete', ['calendar' => $calendar, 'photo' => $photo]) }}
The method in the controller:
public function deletePhoto(Calendar $calendar, Photo $photo)
{
$calendar->photos()->where('id', $photo->id)->delete();
return redirect()->action('CalendarController@edit');
}
But I have photo's list in edit calendar's event view. I have method delete inside CalendarController. I am trying your answer but it doesn't work :/ I'm trying to create a calendar event edit. I wanted to delete and add photos from the event editing level. Therefore, deleting from the calendar controller level.
– Giacomo
Nov 25 '18 at 19:46
@Giacomo My first approach is the restful approach, and it should work if you have the resources created as they should be. You can check out my edited answer if it does help for your scenario.
– nakov
Nov 25 '18 at 19:53
I'm not saying it does not work. Just after clicking the link and confirming the deletion, nothing happens.
– Giacomo
Nov 25 '18 at 20:04
@Giacomo That's why I said that you should submit the form. I don't see the content on yourconfirm
function in JS. You can share it with me and I can help.
– nakov
Nov 25 '18 at 20:08
Oki, one moment
– Giacomo
Nov 25 '18 at 20:09
|
show 3 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53470869%2flaravel-delete-function-how-to-delete-photo-from-calendars-event%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You use the same $id
to find the photo and the calendar instance.
GET request is not recommended for deleting a resource, so a better approach would be in your routes you can have something like this:
Route::delete('photo/{photo}', 'PhotosController@delete')->name('photo.delete');
Then in your view, you should surround the button with a Form, for example:
<form method="POST" action="{{ route('photo.delete', $photo) }}">
@csrf
@method("DELETE")
<a onClick="return confirm('Are you sure?')"><i class="fas fa-times"></i>Remove</a>
</form>
Then your confirm
function in JS should submit the form if the user accepts to delete the photo. And also remember to return false as default in the confirm function so it does not submits the form by default.
Your controller will then be:
public function delete(Photo $photo)
{
$photo->delete();
return redirect()->back();
}
--- EDIT
Route::delete('calendar/{calendar}/photo/{photo}', 'CalendarController@deletePhoto')->name('photo.delete');
and the action in the form can be:
{{ route('photo.delete', ['calendar' => $calendar, 'photo' => $photo]) }}
The method in the controller:
public function deletePhoto(Calendar $calendar, Photo $photo)
{
$calendar->photos()->where('id', $photo->id)->delete();
return redirect()->action('CalendarController@edit');
}
But I have photo's list in edit calendar's event view. I have method delete inside CalendarController. I am trying your answer but it doesn't work :/ I'm trying to create a calendar event edit. I wanted to delete and add photos from the event editing level. Therefore, deleting from the calendar controller level.
– Giacomo
Nov 25 '18 at 19:46
@Giacomo My first approach is the restful approach, and it should work if you have the resources created as they should be. You can check out my edited answer if it does help for your scenario.
– nakov
Nov 25 '18 at 19:53
I'm not saying it does not work. Just after clicking the link and confirming the deletion, nothing happens.
– Giacomo
Nov 25 '18 at 20:04
@Giacomo That's why I said that you should submit the form. I don't see the content on yourconfirm
function in JS. You can share it with me and I can help.
– nakov
Nov 25 '18 at 20:08
Oki, one moment
– Giacomo
Nov 25 '18 at 20:09
|
show 3 more comments
You use the same $id
to find the photo and the calendar instance.
GET request is not recommended for deleting a resource, so a better approach would be in your routes you can have something like this:
Route::delete('photo/{photo}', 'PhotosController@delete')->name('photo.delete');
Then in your view, you should surround the button with a Form, for example:
<form method="POST" action="{{ route('photo.delete', $photo) }}">
@csrf
@method("DELETE")
<a onClick="return confirm('Are you sure?')"><i class="fas fa-times"></i>Remove</a>
</form>
Then your confirm
function in JS should submit the form if the user accepts to delete the photo. And also remember to return false as default in the confirm function so it does not submits the form by default.
Your controller will then be:
public function delete(Photo $photo)
{
$photo->delete();
return redirect()->back();
}
--- EDIT
Route::delete('calendar/{calendar}/photo/{photo}', 'CalendarController@deletePhoto')->name('photo.delete');
and the action in the form can be:
{{ route('photo.delete', ['calendar' => $calendar, 'photo' => $photo]) }}
The method in the controller:
public function deletePhoto(Calendar $calendar, Photo $photo)
{
$calendar->photos()->where('id', $photo->id)->delete();
return redirect()->action('CalendarController@edit');
}
But I have photo's list in edit calendar's event view. I have method delete inside CalendarController. I am trying your answer but it doesn't work :/ I'm trying to create a calendar event edit. I wanted to delete and add photos from the event editing level. Therefore, deleting from the calendar controller level.
– Giacomo
Nov 25 '18 at 19:46
@Giacomo My first approach is the restful approach, and it should work if you have the resources created as they should be. You can check out my edited answer if it does help for your scenario.
– nakov
Nov 25 '18 at 19:53
I'm not saying it does not work. Just after clicking the link and confirming the deletion, nothing happens.
– Giacomo
Nov 25 '18 at 20:04
@Giacomo That's why I said that you should submit the form. I don't see the content on yourconfirm
function in JS. You can share it with me and I can help.
– nakov
Nov 25 '18 at 20:08
Oki, one moment
– Giacomo
Nov 25 '18 at 20:09
|
show 3 more comments
You use the same $id
to find the photo and the calendar instance.
GET request is not recommended for deleting a resource, so a better approach would be in your routes you can have something like this:
Route::delete('photo/{photo}', 'PhotosController@delete')->name('photo.delete');
Then in your view, you should surround the button with a Form, for example:
<form method="POST" action="{{ route('photo.delete', $photo) }}">
@csrf
@method("DELETE")
<a onClick="return confirm('Are you sure?')"><i class="fas fa-times"></i>Remove</a>
</form>
Then your confirm
function in JS should submit the form if the user accepts to delete the photo. And also remember to return false as default in the confirm function so it does not submits the form by default.
Your controller will then be:
public function delete(Photo $photo)
{
$photo->delete();
return redirect()->back();
}
--- EDIT
Route::delete('calendar/{calendar}/photo/{photo}', 'CalendarController@deletePhoto')->name('photo.delete');
and the action in the form can be:
{{ route('photo.delete', ['calendar' => $calendar, 'photo' => $photo]) }}
The method in the controller:
public function deletePhoto(Calendar $calendar, Photo $photo)
{
$calendar->photos()->where('id', $photo->id)->delete();
return redirect()->action('CalendarController@edit');
}
You use the same $id
to find the photo and the calendar instance.
GET request is not recommended for deleting a resource, so a better approach would be in your routes you can have something like this:
Route::delete('photo/{photo}', 'PhotosController@delete')->name('photo.delete');
Then in your view, you should surround the button with a Form, for example:
<form method="POST" action="{{ route('photo.delete', $photo) }}">
@csrf
@method("DELETE")
<a onClick="return confirm('Are you sure?')"><i class="fas fa-times"></i>Remove</a>
</form>
Then your confirm
function in JS should submit the form if the user accepts to delete the photo. And also remember to return false as default in the confirm function so it does not submits the form by default.
Your controller will then be:
public function delete(Photo $photo)
{
$photo->delete();
return redirect()->back();
}
--- EDIT
Route::delete('calendar/{calendar}/photo/{photo}', 'CalendarController@deletePhoto')->name('photo.delete');
and the action in the form can be:
{{ route('photo.delete', ['calendar' => $calendar, 'photo' => $photo]) }}
The method in the controller:
public function deletePhoto(Calendar $calendar, Photo $photo)
{
$calendar->photos()->where('id', $photo->id)->delete();
return redirect()->action('CalendarController@edit');
}
edited Nov 25 '18 at 19:52
answered Nov 25 '18 at 19:33
nakovnakov
2,439189
2,439189
But I have photo's list in edit calendar's event view. I have method delete inside CalendarController. I am trying your answer but it doesn't work :/ I'm trying to create a calendar event edit. I wanted to delete and add photos from the event editing level. Therefore, deleting from the calendar controller level.
– Giacomo
Nov 25 '18 at 19:46
@Giacomo My first approach is the restful approach, and it should work if you have the resources created as they should be. You can check out my edited answer if it does help for your scenario.
– nakov
Nov 25 '18 at 19:53
I'm not saying it does not work. Just after clicking the link and confirming the deletion, nothing happens.
– Giacomo
Nov 25 '18 at 20:04
@Giacomo That's why I said that you should submit the form. I don't see the content on yourconfirm
function in JS. You can share it with me and I can help.
– nakov
Nov 25 '18 at 20:08
Oki, one moment
– Giacomo
Nov 25 '18 at 20:09
|
show 3 more comments
But I have photo's list in edit calendar's event view. I have method delete inside CalendarController. I am trying your answer but it doesn't work :/ I'm trying to create a calendar event edit. I wanted to delete and add photos from the event editing level. Therefore, deleting from the calendar controller level.
– Giacomo
Nov 25 '18 at 19:46
@Giacomo My first approach is the restful approach, and it should work if you have the resources created as they should be. You can check out my edited answer if it does help for your scenario.
– nakov
Nov 25 '18 at 19:53
I'm not saying it does not work. Just after clicking the link and confirming the deletion, nothing happens.
– Giacomo
Nov 25 '18 at 20:04
@Giacomo That's why I said that you should submit the form. I don't see the content on yourconfirm
function in JS. You can share it with me and I can help.
– nakov
Nov 25 '18 at 20:08
Oki, one moment
– Giacomo
Nov 25 '18 at 20:09
But I have photo's list in edit calendar's event view. I have method delete inside CalendarController. I am trying your answer but it doesn't work :/ I'm trying to create a calendar event edit. I wanted to delete and add photos from the event editing level. Therefore, deleting from the calendar controller level.
– Giacomo
Nov 25 '18 at 19:46
But I have photo's list in edit calendar's event view. I have method delete inside CalendarController. I am trying your answer but it doesn't work :/ I'm trying to create a calendar event edit. I wanted to delete and add photos from the event editing level. Therefore, deleting from the calendar controller level.
– Giacomo
Nov 25 '18 at 19:46
@Giacomo My first approach is the restful approach, and it should work if you have the resources created as they should be. You can check out my edited answer if it does help for your scenario.
– nakov
Nov 25 '18 at 19:53
@Giacomo My first approach is the restful approach, and it should work if you have the resources created as they should be. You can check out my edited answer if it does help for your scenario.
– nakov
Nov 25 '18 at 19:53
I'm not saying it does not work. Just after clicking the link and confirming the deletion, nothing happens.
– Giacomo
Nov 25 '18 at 20:04
I'm not saying it does not work. Just after clicking the link and confirming the deletion, nothing happens.
– Giacomo
Nov 25 '18 at 20:04
@Giacomo That's why I said that you should submit the form. I don't see the content on your
confirm
function in JS. You can share it with me and I can help.– nakov
Nov 25 '18 at 20:08
@Giacomo That's why I said that you should submit the form. I don't see the content on your
confirm
function in JS. You can share it with me and I can help.– nakov
Nov 25 '18 at 20:08
Oki, one moment
– Giacomo
Nov 25 '18 at 20:09
Oki, one moment
– Giacomo
Nov 25 '18 at 20:09
|
show 3 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53470869%2flaravel-delete-function-how-to-delete-photo-from-calendars-event%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The error you're seeing suggests that
$calRepo->find($id);
isn't finding aCalendar
and is returningnull
. When you're then doing$calendar->photos(...)
you're calling a method onnull
which doesn't make sense. Does the ID in this case definitely refer to an actual calendar in your database?– Jonathon
Nov 25 '18 at 19:28
Also, in your template it looks like you're passing the ID of the photo but in your controller you're expecting
$id
to be the ID of the calendar which could explain what's going wrong– Jonathon
Nov 25 '18 at 19:30