1

In my website, I have a page where users can see their orders. In this table, I want to be able to delete the order by clicking a link. However, everything i tried so far isn't working. I have no idea what I'm doing wrong or what I can do to make I work. It keeps giving me a 404 error.

My Route:

Route::get('destroy/{$id}', 'AccountController@destroy');

My Controller function:

public function destroy($id)
{
    RestaurantModel::where('id', $id)->delete();

    return back('/');
}

My Model: Don't mind the model name.

class RestaurantModel extends Model
{
protected $table = 'orders';
protected $primarykey = 'orderNumber';
} 

The row from the table in my view: The delete function is at the back of the code.

@foreach ($orders as $order)
            <tr>
                 <td><a href="">{{{ $order->orderNumber }}}</a></td>
                 <td>{{{ $order->orderDate }}}</td><td>{{{ $order->shippedDate }}}</td>
                 <td>{{{ $order->status }}}</td>
                 <td>{{{ $order->comments }}}</td>
                 <td>{{{ $order->customerNumber }}}</td>
                 <td><a href="{{ action('AccountController@destroy', $order->orderNumber) }}">Delete order</a></td>
            </tr>
@endforeach

I hope someone can help me with my problem. I've been stuck on this for a while now.

4
  • did you tried my answer? Commented Jan 14, 2019 at 9:14
  • Yes, I did, however, its still giving me a 404 error. Commented Jan 14, 2019 at 9:16
  • please refer to this post stackoverflow.com/questions/44113969/… Commented Jan 14, 2019 at 9:20
  • Please share the URL for 404 page. Commented Jan 14, 2019 at 9:26

1 Answer 1

1

Try changing your route

Route::get('destroy/{$id}', 'AccountController@destroy');

to

Route::get('destroy/{id}', 'AccountController@destroy');
Sign up to request clarification or add additional context in comments.

5 Comments

It's still giving me a 404 not found error. I assume the problem is my route?
Changed answer to what I think might be the problem, could you try and post results?
I tried changing my route to the route you provided for me. It deleted the row from the database, but its still throwing errors. This is the error it gave me. Argument 2 passed to Symfony\Component\HttpFoundation\RedirectResponse::__construct() must be of the type integer, string given, called in D:\wamp64\www\restaurant\vendor\laravel\framework\src\Illuminate\Routing\Redirector.php on line 203
Thats good! It's now getting in the method. However, there's still an error then. Change your return back('/'); to either return redirect()->back(); or return redirect('/);. redirect()->back(); redirects the user to the previous page, and redirect('/'); redirects the user to the '/' endpoint.
It worked! thank you so much for your help, you're a hero!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.