Remove an owl carousel using Laravel, Vue.js, and Axios

I've implemented a sleek slider on my website to showcase images with accompanying text to visitors. The slider utilizes owl carousel within a vue component and is functioning properly. Now, I'm attempting to add a delete button so that users who created the slider can remove any unwanted images.

My starting point was the controller:

public function destroy(Request $request, Slide $slide)
{
    $slide = Slide::where('id', $request->id);
    $slide->delete();

    return response()->json($slide, 200);
}

Additionally, I have route groups set up as follows:

Route::group(['prefix' => '/{area}'], function () {
    Route::group(['middleware' => ['auth']], function () {
        Route::post('/{hustle}', 'Slides\SlideController@save')->name('slide.save');
        Route::delete('/{hustle}/slider/{slide}', 'Slides\SlideController@destroy')->name('slide.destroy');
    });
    Route::get('/{hustle}/slider', 'Hustle\SliderController@index');
});

Here's what the delete button code looks like:

<button @click="deleteSlide">Delete</button> {{ slider.uid }}

Lastly, here is the method being used:

methods: {
  getSlider () {
    var that = this;
    axios.get( '/' + this.areaId + '/' + this.hustleId + '/slider').then((response) => {
      that.sliders = response.data;
      console.log(that.sliders);
      Vue.nextTick(function() {

        $('#sliders').owlCarousel({
          items:1,
        });

      });
    })
    .catch(error => {
      console.log(error)
      this.errored = true
    });
  },

  deleteSlide (slider) {
    var that = this;
    axios.delete('/' + this.areaId + '/' + this.hustleId + '/slider/' + this.sliderId).then((response) => {
      that.slider.splice(slider, 1)
      console.log(that.sliderId);
    });

  }
},

Despite my efforts, I keep encountering a "500 bad method" error message. Even with the debug bar enabled, the issue persists. Any ideas on how to resolve this?

Answer №1

Unfortunately, I lack the reputation to leave a comment; however...

Upon initial inspection, it appears that your route requires two parameters: hustle and slide.
Yet, you are passing four parameters to axios: area, hustle, a slider string, and an id

Therefore, this constitutes a completely distinct route :)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using JQuery to implement custom validation on a text field is an effective way

How can I validate a text field using Regex and create my own validation rule for starting with "com."? Can you provide me with an example of how to do this? I want the text field to only accept values that start with com. <input id="appPackage" name=" ...

How can you include a key event handler that specifically looks out for the Space key being pressed?

When a user presses the Enter key (and button is in focus), the button opens. However, I would like to also open the link button when the user presses the space bar. Buttons should be activated using the Space key, while links should be activated with the ...

Reference itself in a VueJS template element

I have a situation where I need to apply an 'active' class to a specific div element when it is clicked. I am attempting to bind the 'active' class based on a variable 'activeSlide' being equal to the element. v-bind:class="{ ...

Troubleshooting the issue of VSCode's CTRL+Click feature not navigating to definitions within HTML tags in Vue files

Currently, I am utilizing VSCode along with all the necessary Vue extensions (including Vetur, which is supposed to handle going to definitions), but I have encountered an issue. When working in a .vue file type, I am unable to use CTRL+Click to navigate t ...

Disabling the experimental app directory feature in NextJs

I've been working on a real-life project and decided to test out the new App directory feature that comes with Next.js version 13. However, I encountered some issues such as images and fonts not loading properly. Now, I'm looking to opt out of th ...

Is it possible to arrange two items in one column and the rest as columns in MaterialUI Grid?

I need help arranging my arrows in a MaterialUI grid where one points up and the other points down. How can I achieve this layout? Attached below is an image of my current setup and the desired outcome. Here is my code: <Paper className={classes.paper ...

Enhance the appearance of Google Maps by incorporating gradient effects, box shadows, or other similar visual

How can I add a linear gradient to Google Maps? Below is my code snippet. HTML <div id="map"></div> CSS #map{ height:100vh; background: linear-gradient(90deg, #f7f8fa 0%, rgba(247, 248, 250, 0) 18.73%), linear-gradient(180deg, # ...

What methods are there to verify computed properties in VueJS?

I'm currently working with VueJS through Vue CLI, which means all my components are in the .vue format. Within one of my components, I have an array named fields located in the data section. //Component.vue data() { return { fields : [{"name" ...

Issue with updated form input failing to submit the latest value

Below is my Vue template code: <form action="[path]/post.php" ref="vueForm" method="post"> <input type="hidden" name="hiddenfield" :value="newValue"> <input type="button" value="new value and submit" @click="changeVal(456)"> </form> ...

What exactly is Bootstrap - a CSS framework, a JavaScript framework, or a combination

Being new to Bootstrap, I have taken the time to explore What is Bootstrap? as well as http://getbootstrap.com/. From what I understand so far, Bootstrap is a CSS framework that aids in creating responsive designs that can adapt to various devices. Essent ...

What is the process for sending data to a node server using POST and receiving a responseText from it through GET?

Here is an example where I'm trying to send data from a JavaScript client to an Express Node server, validate the data against the database on the server, and respond once the verification process is complete. The data object in newHttpRequest.send(da ...

What is the best way to hide only the rows in a table when it is clicked using JavaScript?

Is there a way to hide rows in these tables by clicking on the table head? I'm currently using bootstrap 5 so JQuery is not an option. <table class="table table-info table-bordered"> <thead id="tablea"> ...

How can Selenium in Python be used to click a JavaScript button?

I need help automating the click of a button on a webpage using selenium Here is the HTML for the button: <div class="wdpv_vote_up "> <input value="7787" type="hidden"> <input class="wdpv_blog_id" value="1" type="hidden"> </div& ...

Using AJAX, JQuery, and PHP to convert a given name to match the columns in a query, utilizing the data sent

One thing that I'm wondering about is how PHP handles my ajax requests. For example, consider the following code snippet: $("#addUser").on('click', '.btnAddSubmitFormModal', function() { $.post("add.php", { ...

How can you use HTML, CSS, and JavaScript to group objects with one color and then change the color of one specific object?

I have a set of 6 labels that act as buttons. When one is clicked, it changes from white to blue. If another label is clicked, the previously blue label turns white and the newly clicked one turns blue. Currently, the code below sets all labels to white b ...

receiving an undefined value from a remote JSON object in Node.js

I have been struggling to extract the specific contents of a JSON api without success. Despite my best efforts, the console always returns undefined. My goal is to retrieve and display only the Question object from the JSON data. After spending several h ...

Spacing issues while utilizing the <textarea> element

<tr> <td> <b>Escalation: </td></b> <td> <TextArea name='escalation' onKeyDown=\"limitText(this.form.escalation,this.form.countdown,100);\" onKeyUp=\"limitText ...

Why is the location search not staying centered after resizing the map on Google Maps?

I am currently working on integrating Angular with Google Maps. I need to add some markers along with location search functionality. Additionally, I am including location information in a form. When the addMarker button is clicked, a form opens and the map ...

Ways to modify an image with Laravel's controller module

I am facing an issue with updating the user image. I have implemented the following controller for updating the image. Can someone point out what could be wrong in the controller function? View section : <div class="form-group"> <lab ...

Ditch the if-else ladder approach and instead, opt for implementing a strategic design

I am currently working on implementing a strategic design pattern. Here is a simple if-else ladder that I have: if(dataKeyinresponse === 'year') { bsd = new Date(moment(new Date(item['key'])).startOf('year&apos ...