Deleting a user in Laravel results in the return of a link containing their unique

I'm currently developing a 1-page CRUD application using Laravel, and I've encountered an issue. Whenever I delete a user that was just edited, I either get a blank page or a 404 error. It seems like this happens because the link it returns is: admin/user/{id}. I would like to modify it so that it returns the base URL: admin/user without the {id} at the end. Is there a way to achieve this?

Controller destroy code:

public function destroy($id)
    {
       $user = User::find($id);
       $user->delete();
       return back();
    }

Answer №1

Once a record has been deleted, it cannot be retrieved.

If you wish to go back, simply redirect to a specific route.

public function destroy($id)
{
    $user = User::find($id);
    $user->delete();
    return redirect()->route('admin.user')->with('success', 'Your message of success');
}

You can also display a flash message when your URL redirects to the page.

Happy Coding!!! 🚀

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

What are some ways to divide drop targets with React DnD?

In my React Dnd v16.0.1 project, I am dynamically rendering containers and images from JSON data using map function. The issue I'm facing is with two droppable containers where only one should accept dropped images. However, when I drop an image on th ...

Expanding box geometry from a single side in Three.js

Just starting out with three.js and my first task was to create a box geometry that could be increased from only one side. Issue : When increasing the width or height of an object, both sides automatically expand. Check out this jsFiddle Example I waste ...

No instances are returned by Processing.instances

I am experiencing an issue with a webpage that is running 2 processing sketches. I came across a suggestion to call Processing.instances[0].exit() in response to a question on dynamically unloading a Processing JS sketch from canvas. However, when I attem ...

Tips on modifying the mention plugin's output DOM element within ckeditor5

Resulting Output <span class="mention" data-mention="@lilypad">@lilypad</span> Attempted the following, writer.createUIElement( 'span', null, function( domDocument ) { const domElement = this.toDomElement( domDoc ...

Iterate through an array while only mapping X number of elements during each iteration

Currently, I am working on a project that involves creating a grid of client logos using Tailwind CSS, react, and GSAP. The paths to the client logos are fetched from a JSON file. Since the list of client logos is quite lengthy, I decided it would be inter ...

Tips on automating the process of moving overflowing elements into a dropdown menu

Challenge Description In need of a dynamic navigation bar, I faced the problem of displaying only the first X items on one line and have the remaining items hidden in a "Show more" dropdown. The challenge was to calculate the width of each item accurately ...

Analyzing registration details stored in an array against user login credentials

With two buttons available - one for sign up and the other for log in, my goal is to gather input form values from the sign-up section into an array. Following this, I aim to compare the user input from the sign-up with that of the log-in, informing the us ...

Employing the $(this) in jQuery to modify a separate element

Hey, I have a question about changing attributes in jQuery. I already know how to change an attribute for the same element you hover over... $(".click2play").mouseover(function() { $(this).css({'visibility' : 'hidd ...

displaying a post-end issue on the express server

Currently, I am working on a school project that requires the development of a client-server application. The specific task is to create a webshop that can load products using AJAX. To achieve this, I am utilizing jquery and the $.load() method. Within my ...

Incorporate a JSON file into the body of an HTML document

I'm experiencing an issue with loading a Json file into the html body using the script tag, as illustrated below. Here is a sample of the html file: <html> <head></head> <body> <div id="category"></div> <scrip ...

There is no information available at this time

Currently, I am delving into Angular and am keen on creating a web application that consumes a Restful Web service. The setup of my page is as follows: <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html ng-app="Tri ...

Is there a way to turn off vue.js transitions specifically for testing purposes?

I'm utilizing a vue.js component with the <transition> element for show/hide animations. However, I want to disable the animation for faster testing. How can I achieve this? The solution proposed is * { transition: none !important } in this lin ...

Form a collection of visible table rows without hidden columns

My table allows users to filter out specific rows by selecting a checkbox. When a checkbox is checked, certain rows are hidden. I am trying to create an array with all the rows that are not hidden, but I am having trouble accessing the visibility state of ...

My component is not executing the onClick function as expected

I am facing an issue with a component that I imported into another component. Despite clicking on the component, the onclick function does not execute. Here is the code snippet for the component: const HomeFeedCard = ({ name, image, published, quantity, w ...

The npm package installation process encountered difficulties in accessing the Chart.Js library

Currently, I am in the process of developing a web application that tracks and logs hours spent on various skills or activities. The data is then presented to the user through a bar graph created using Chart.js. Initially, I was able to display a mock grap ...

Programmatically simulate a text cursor activation as if the user has physically clicked on the input

I have been attempting to input a value into a text field using JavaScript, similar to the Gmail email input tag. However, I encountered an issue with some fancy animations that are tied to certain events which I am unsure how to trigger, illustrated in th ...

Submit data using PHP and then forward the user to the next page

I am looking for a way to send data to a page using $_POST and redirection without relying on JavaScript or manually writing HTML forms. Is there a solution that involves CURL instead? Any guidance on how to achieve this would be greatly appreciated! Thank ...

Using a navigation bar as a structural component in React

I have a new app in development that features a search bar on every page as part of the layout. When a user conducts a search, the results are displayed and they can click on a result to view more details in a separate component. My main question is regar ...

Using a controller variable inside an AngularJS directive requires proper binding and referencing within the

Can someone help me with using a controller variable inside a directive? I have tried using popoverHtml inside the scope in the directive but it seems that when I add a type like this, it does not work: For example: scope: { popoverHtml:'@', typ ...

Updating the parameters when clicking on each pagination button: A guide

Does anyone have advice on implementing pagination? I am currently working on loading a datatable with a few records initially. Once the page is loaded, I want to be able to click on pagination buttons like next or any pagination buttons to display a new s ...