Home » Php » I just can't delete one of my user addresses in Laravel

I just can't delete one of my user addresses in Laravel

Posted by: admin June 30, 2018 Leave a comment

Questions:

I’m having some problems when I’m going to delete one of my user’s addresses. I want to let you know that the user has a relation One To Many with the table of Addresses.

Here, I’m just trying to delete the Address through his ‘id’, but it doesn’t work.

UserController

<?php

namespace App\Http\Controllers;
use App\User;
use App\Address;
use Illuminate\Http\Request;
use App\Http\Requests;
use Auth;

class UserController extends Controller
{
   public function deleteAddress(User $user, Address $address) {   
    $address->user->is($user); 

    $address->destroy();

    return redirect()->back();
  }
}

{Routes} Web.php

<?php


 Route::get('/', [
'uses' => '[email protected]',
'as' => 'welcome.index'
 ]);

 Route::get('/products/{product}', [ 
'uses' => '[email protected]',
'as' => 'welcome.show'
 ]);


 Route::group(['middleware' => 'auth'], function() {
 Route::get('/user/profile', [
    'uses' => '[email protected]',
    'as' => 'user.profile'
 ]);

Route::get('/user/profile/account', [
    'uses' => '[email protected]',
    'as' => 'user.account'
]);

Route::patch('/user/profile/account/{user}/name-update',  [
    'uses' => '[email protected]',
    'as' => 'user.nameUpdate'
]);

Route::patch('/user/profile/account/{user}/email-update',  [
    'uses' => '[email protected]',
    'as' => 'user.emailUpdate'
]);

Route::patch('/user/profile/account/{user}/password-update',  [
    'uses' => '[email protected]',
    'as' => 'user.passwordUpdate'
]);

Route::get('/user/profile/address', [
    'uses' => '[email protected]',
    'as' => 'user.address'
]);

Route::post('/user/profile/address/{user}/create', [
    'uses' => '[email protected]',
    'as' => 'user.newAddress'
]);

Route::post('/user/profile/address/{address}/delete', [
    'uses' => '[email protected]',
    'as' => 'user.deleteAddress',
]);

Route::get('/logout', [
    'uses' => '\App\Http\Controllers\Auth\[email protected]',
    'as' => 'logout'
]);
}); 

Auth::routes();

View

Every kind of help is welcomed.

Throwing this error

Answers: