Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LaravelFan's avatar

Routing issue on my vendor's dashboard

Hi,

I'm getting Route [vendor.address] not defined. This is the relevant section:


<div class="dashboard_sidebar">
    <span class="close_icon">
        <i class="far fa-bars dash_bar"></i>
        <i class="far fa-times dash_close"></i>
    </span>
    <a href="dsahboard.html" class="dash_logo"><img src="images/logo.png" alt="logo" class="img-fluid"></a>
    <ul class="dashboard_link">
        <li><a class="active" href="{{ route('vendor.dashboard') }}"><i class="fas fa-tachometer"></i>Dashboard</a></li>
        <li><a href=""><i class="fas fa-list-ul"></i> Orders</a></li>
        <li><a href=""><i class="far fa-star"></i> Reviews</a></li>
        <li><a href="{{ route('vendor.profile') }}"><i class="far fa-user"></i> My Profile</a></li>
        <li><a href="{{ route('vendor.address') }}"><i class="fal fa-gift-card"></i> Addresses</a></li>
        <li>
            <form method="POST" action="{{ route('logout') }}">
                @csrf
                <a href="{{ route('logout') }}"onclick="event.preventDefault();
            this.closest('form').submit();"><i class="far fa-sign-out-alt"></i> Log out</a>
            </form>
        </li>

    </ul>
</div>


This is the vendor.php route:


<?php

use App\Http\Controllers\VendorController;
use App\Http\Controllers\VendorProfileController;
use App\Http\Controllers\VendorAddressController;
use Illuminate\Support\Facades\Route;


/** This updates the vendor's username, email and password (copied from Laravel Breeze route) */

Route::middleware(['auth', 'verified', 'role:vendor'])
    
    ->group(function () {
        Route::get('dashboard', [VendorController::class, 'dashboard'])->name('dashboard');
        Route::get('profile', [VendorProfileController::class, 'index'])->name('profile');
        Route::put('profile', [VendorProfileController::class, 'updateProfile'])->name('profile.update');
        Route::post('profile', [VendorProfileController::class, 'updatePassword'])->name('profile.update.password');
    });

/** Vendor's address routes */

Route::get('vendor/dashboard/address', [VendorAddressController::class, 'address'])->name('vendor.address');
Route::get('vendor/dashboard/address/create', [VendorAddressController::class, 'create'])->name('vendor.address.create');
Route::post('vendor/dashboard/address', [VendorAddressController::class, 'store'])->name('vendor.address.store');
Route::get('vendor/dashboard/address/{id}/edit', [VendorAddressController::class, 'edit'])->name('vendor.address.edit');
Route::put('vendor/dashboard/address/{id}', [VendorAddressController::class, 'update'])->name('vendor.address.update');
Route::delete('vendor/dashboard/address/{id}', [VendorAddressController::class, 'destroy'])->name('vendor.address.destroy');

This is the VendorAddressController:


<?php

namespace App\Http\Controllers;

use App\Models\VendorAddress;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;


class VendorAddressController extends Controller
{
    // This will return the address page
    public function address()
    {
        $addresses = VendorAddress::where('user_id', Auth::user()->id)->get();
        return view('vendor.dashboard.address.index', compact('addresses'));
    }

    // This will return the create page
    public function create()
    {
        return view('vendor.dashboard.address.create');
    }

    public function store(Request $request)
    {
        // This adds validation to the user input fields
        $request->validate([
            'name' => ['required', 'max:200'],
            'email' => ['required', 'max:200', 'email'],
            'phone' => ['required', 'max:200'],
            'country' => ['required', 'max:200'],
            'state' => ['required', 'max:200'],
            'city' => ['required', 'max:200'],
            'zip' => ['required', 'max:200'],
            'address' => ['required', 'max:200'],

        ]);

        // This stores the user input into the database
        $address = new VendorAddress();
        $address->user_id = Auth::user()->id;
        $address->name = $request->name;
        $address->email = $request->email;
        $address->phone = $request->phone;
        $address->country = $request->country;
        $address->state = $request->state;
        $address->city = $request->city;
        $address->zip = $request->zip;
        $address->address = $request->address;
        $address->save();

        // This displays the toast message 
        toastr('Updated Successfully!')->success('Address successfully added!');
        return redirect()->route('vendor.address');
    }

    // This will update an existing address

    public function edit(string $id)
    {
        $address = VendorAddress::findOrFail($id);
        return view('vendor.dashboard.address.edit', compact('address'));
    }

    public function update(Request $request, string $id)
    {
        $request->validate([
            'name' => ['required', 'max:200'],
            'email' => ['required', 'max:200', 'email'],
            'phone' => ['required', 'max:200'],
            'country' => ['required', 'max:200'],
            'state' => ['required', 'max:200'],
            'city' => ['required', 'max:200'],
            'zip' => ['required', 'max:200'],
            'address' => ['required'],
        ]);

        $address = Vendoraddress::findOrFail($id);
        $address->user_id = Auth::user()->id;
        $address->name = $request->name;
        $address->email = $request->email;
        $address->phone = $request->phone;
        $address->country = $request->country;
        $address->state = $request->state;
        $address->city = $request->city;
        $address->zip = $request->zip;
        $address->address = $request->address;
        $address->save();

        toastr('Updated Successfully!', 'success', 'Success')->success('Updated Successfully!');

        return redirect()->route('vendor.address');
    }

    // This will delete an address

    public function destroy(string $id)
    {
        $address = VendorAddress::findOrFail($id);
        $address->delete();

        return response(['status' => 'success', 'message' => 'Deleted Successfully!']);
    }
}


Grateful for your guidance.

0 likes
36 replies
gych's avatar

When you type php artisan route:list in the terminal, can you see the route in the list?

1 like
Snapey's avatar

php artisan route:list

always

1 like
LaravelFan's avatar

This is what I got:


GET|HEAD  vendor/vendor/dashboard/address ............................................................... vendor.vendor.address › VendorAddressController@address
  POST      vendor/vendor/dashboard/address ........................................................... vendor.vendor.address.store › VendorAddressController@store

Snapey's avatar

so there is your answer. you have a route group with vendor prefix, so the route is called vendor.vendor.account

LaravelFan's avatar

@Snapey Hi, Yes, that did it:

<li><a href="{{ route('vendor.vendor.address') }}"><i class="fal fa-gift-card"></i> Addresses</a></li>

But I'm wondering, why does this work

<li><a href="{{ route('vendor.profile') }}"><i class="far fa-user"></i> My Profile</a></li> 

without having to add vendor.vendor.profile?

LaravelFan's avatar

Because this is what I've in the VendorAddressController:


<?php

namespace App\Http\Controllers;

use App\Models\VendorAddress;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;


class VendorAddressController extends Controller
{
    // This will return the address page
    public function address()
    {
        $addresses = VendorAddress::where('user_id', Auth::user()->id)->get();
        return view('vendor.dashboard.address.index', compact('addresses'));
    }

    // This will return the create page
    public function create()
    {
        return view('vendor.dashboard.address.create');
    }

    public function store(Request $request)
    {
        // This adds validation to the user input fields
        $request->validate([
            'name' => ['required', 'max:200'],
            'email' => ['required', 'max:200', 'email'],
            'phone' => ['required', 'max:200'],
            'country' => ['required', 'max:200'],
            'state' => ['required', 'max:200'],
            'city' => ['required', 'max:200'],
            'zip' => ['required', 'max:200'],
            'address' => ['required', 'max:200'],

        ]);

        // This stores the user input into the database
        $address = new VendorAddress();
        $address->user_id = Auth::user()->id;
        $address->name = $request->name;
        $address->email = $request->email;
        $address->phone = $request->phone;
        $address->country = $request->country;
        $address->state = $request->state;
        $address->city = $request->city;
        $address->zip = $request->zip;
        $address->address = $request->address;
        $address->save();

        // This displays the toast message 
        toastr('Updated Successfully!')->success('Address successfully added!');
        return redirect()->route('vendor.address');
    }

    // This will update an existing address

    public function edit(string $id)
    {
        $address = VendorAddress::findOrFail($id);
        return view('vendor.dashboard.address.edit', compact('address'));
    }

    public function update(Request $request, string $id)
    {
        $request->validate([
            'name' => ['required', 'max:200'],
            'email' => ['required', 'max:200', 'email'],
            'phone' => ['required', 'max:200'],
            'country' => ['required', 'max:200'],
            'state' => ['required', 'max:200'],
            'city' => ['required', 'max:200'],
            'zip' => ['required', 'max:200'],
            'address' => ['required'],
        ]);

        $address = Vendoraddress::findOrFail($id);
        $address->user_id = Auth::user()->id;
        $address->name = $request->name;
        $address->email = $request->email;
        $address->phone = $request->phone;
        $address->country = $request->country;
        $address->state = $request->state;
        $address->city = $request->city;
        $address->zip = $request->zip;
        $address->address = $request->address;
        $address->save();

        toastr('Updated Successfully!', 'success', 'Success')->success('Updated Successfully!');

        return redirect()->route('vendor.address');
    }

    // This will delete an address

    public function destroy(string $id)
    {
        $address = VendorAddress::findOrFail($id);
        $address->delete();

        return response(['status' => 'success', 'message' => 'Deleted Successfully!']);
    }
}

Snapey's avatar

doesnt matter what is in the controller

names are configured in the routes file, but you dont seem to have fully shared that. Im guess8ng for profile you used the route vendor/profile ?

LaravelFan's avatar

@Snapey I added index to this route:


Route::get('vendor/dashboard/address.index', [VendorAddressController::class, 'address'])->name('vendor.address');

This is inside the VendorAddressController:


// This will return the address page
public function address()
    {
    $addresses = VendorAddress::where('user_id', Auth::user()->id)->get();
    return view('vendor.dashboard.address.index', compact('addresses'));
    }


But the problem persists.

Snapey's avatar

@Mamunsson

dont have the period

route::get('vendor/dashboard/address.index'

I cannot follow, you just said you fixed it?

I hope you are not running artisan route:cache ?

LaravelFan's avatar

@Snapey Thanks, I fixed the route in question:


Route::get('vendor/dashboard/address/index', [VendorAddressController::class, 'address'])->name('vendor.address');


    public function address()
    {
        $addresses = VendorAddress::where('user_id', Auth::user()->id)->get();
        return view('vendor.dashboard.address.index', compact('addresses'));
    }

But I keep getting Route [vendor.address] not defined.

LaravelFan's avatar

  GET|HEAD  / ..................................................................................................................................................... 
  GET|HEAD  _debugbar/assets/javascript ............................................................... debugbar.assets.js › Barryvdh\Debugbar › AssetController@js
  GET|HEAD  _debugbar/assets/stylesheets ............................................................ debugbar.assets.css › Barryvdh\Debugbar › AssetController@css
  DELETE    _debugbar/cache/{key}/{tags?} ...................................................... debugbar.cache.delete › Barryvdh\Debugbar › CacheController@delete
  GET|HEAD  _debugbar/clockwork/{id} ..................................................... debugbar.clockwork › Barryvdh\Debugbar › OpenHandlerController@clockwork
  GET|HEAD  _debugbar/open ................................................................ debugbar.openhandler › Barryvdh\Debugbar › OpenHandlerController@handle
  POST      _ignition/execute-solution .............................................. ignition.executeSolution › Spatie\LaravelIgnition › ExecuteSolutionController
  GET|HEAD  _ignition/health-check .......................................................... ignition.healthCheck › Spatie\LaravelIgnition › HealthCheckController
  POST      _ignition/update-config ....................................................... ignition.updateConfig › Spatie\LaravelIgnition › UpdateConfigController
  GET|HEAD  about ................................................................................................................... about › AboutController@about
  GET|HEAD  add-to-cart/{product_id} ....................................................................................... add-to-cart › CartController@addToCart
  GET|HEAD  admin/admin/login ................................................................................................. admin.login › AdminController@login
  GET|HEAD  admin/dashboard ........................................................................................... admin.dashboard › AdminController@dashboard
  GET|HEAD  admin/profile ................................................................................................. admin.profile › ProfileController@index
  POST      admin/profile/update ........................................................................... admin.profile.update › ProfileController@updateProfile
  POST      admin/profile/update/password ................................................................ admin.password.update › ProfileController@updatePassword
  GET|HEAD  api/user .............................................................................................................................................. 
  GET|HEAD  auto .................................................................................................................................................. 
  GET|HEAD  cart ....................................................................................................................... cart › CartController@cart
  GET|HEAD  checkout .............................................................................................................................................. 
  GET|HEAD  confirm-password ........................................................................... password.confirm › Auth\ConfirmablePasswordController@show
  POST      confirm-password ............................................................................................. Auth\ConfirmablePasswordController@store
  GET|HEAD  create-role ........................................................................................................................................... 
  GET|HEAD  damen-mode ...................................................................................................................... DamenController@index
  GET|HEAD  elektronik ............................................................................................................................................ 
  POST      email/verification-notification ................................................ verification.send › Auth\EmailVerificationNotificationController@store
  GET|HEAD  forgot-password ............................................................................ password.request › Auth\PasswordResetLinkController@create
  POST      forgot-password ............................................................................... password.email › Auth\PasswordResetLinkController@store
  GET|HEAD  herren-mode ........................................................................................................................................... 
  GET|HEAD  immobilien ............................................................................................................................................ 
  GET|HEAD  impressum ............................................................................................................................................. 
  GET|HEAD  index ................................................................................................................................................. 
  GET|HEAD  kontakt ............................................................................................................................................... 
  GET|HEAD  login .............................................................................................. login › Auth\AuthenticatedSessionController@create
  POST      login ....................................................................................................... Auth\AuthenticatedSessionController@store
  GET|HEAD  logout ........................................................................................... logout › Auth\AuthenticatedSessionController@destroy
  GET|HEAD  moebel ................................................................................................................................................ 
  PUT       password ............................................................................................. password.update › Auth\PasswordController@update
  GET|HEAD  product/{id} ................................................................................................. product.show › ProductController@product
  GET|HEAD  profile ......................................................................................................... profile.edit › ProfileController@edit
  PATCH     profile ..................................................................................................... profile.update › ProfileController@update
  DELETE    profile ................................................................................................... profile.destroy › ProfileController@destroy
  GET|HEAD  qty-decrement/{rowId} ..................................................................................... qty-decrement › CartController@qtyDecrement
  GET|HEAD  qty-increment/{rowId} ..................................................................................... qty-increment › CartController@qtyIncrement
  GET|HEAD  register .............................................................................................. register › Auth\RegisteredUserController@create
  POST      register .......................................................................................................... Auth\RegisteredUserController@store
  GET|HEAD  registrierung ................................................................................... registrierung.create › RegistrierungController@create
  POST      registrierung ..................................................................................... registrierung.store › RegistrierungController@store
  GET|HEAD  remove-product/{rowId} .................................................................................. remove-product › CartController@removeProduct
  GET|HEAD  reset-password ................................................................................. password.reset › ResetPasswordController@showResetForm
  POST      reset-password ...................................................................................... password.store › Auth\NewPasswordController@store
  GET|HEAD  reset-password/{token} ............................................................................. password.reset › Auth\NewPasswordController@create
  GET|HEAD  sanctum/csrf-cookie ................................................................. sanctum.csrf-cookie › Laravel\Sanctum › CsrfCookieController@show
  GET|HEAD  user/address ............................................................................................. user.address › UserAddressController@address
  GET|HEAD  user/dashboard ..................................................................................... user.dashboard › UserDashboardController@dashboard
  GET|HEAD  user/profile ............................................................................................... user.profile › UserProfileController@index
  PUT       user/profile ................................................................................ user.profile.update › UserProfileController@updateProfile
  POST      user/profile ...................................................................... user.profile.update.password › UserProfileController@updatePassword
  POST      user/user/dashboard/address .......................................................................... user.address.store › UserAddressController@store
  PUT       user/user/dashboard/address/{id} ................................................................... user.address.update › UserAddressController@update
  DELETE    user/user/dashboard/address/{id} ................................................................. user.address.destroy › UserAddressController@destroy
  GET|HEAD  user/user/dashboard/address/{id}/edit .................................................................. user.address.edit › UserAddressController@edit
  GET|HEAD  user/user/dashboard/create ......................................................................... user.address.create › UserAddressController@create
  GET|HEAD  vendor/dashboard ........................................................................................ vendor.dashboard › VendorController@dashboard
  GET|HEAD  vendor/profile ......................................................................................... vendor.profile › VendorProfileController@index
  PUT       vendor/profile .......................................................................... vendor.profile.update › VendorProfileController@updateProfile
  POST      vendor/profile ................................................................ vendor.profile.update.password › VendorProfileController@updatePassword
  GET|HEAD  vendor/vendor/dashboard/address ............................................................... vendor.vendor.address › VendorAddressController@address
  POST      vendor/vendor/dashboard/address ........................................................... vendor.vendor.address.store › VendorAddressController@store
  GET|HEAD  vendor/vendor/dashboard/address/create .................................................. vendor.vendor.address.create › VendorAddressController@create
  PUT       vendor/vendor/dashboard/address/{id} .................................................... vendor.vendor.address.update › VendorAddressController@update
  DELETE    vendor/vendor/dashboard/address/{id} .................................................. vendor.vendor.address.destroy › VendorAddressController@destroy
  GET|HEAD  vendor/vendor/dashboard/address/{id}/edit ................................................... vendor.vendor.address.edit › VendorAddressController@edit
  GET|HEAD  verify-email ............................................................................. verification.notice › Auth\EmailVerificationPromptController
  GET|HEAD  verify-email/{id}/{hash} ............................................................................. verification.verify › Auth\VerifyEmailController

LaravelFan's avatar

@Snapey These are all the routes inside the vendor.php route file:


<?php

use App\Http\Controllers\VendorController;
use App\Http\Controllers\VendorProfileController;
use App\Http\Controllers\VendorAddressController;
use Illuminate\Support\Facades\Route;


/** This updates the vendor's username, email and password (copied from Laravel Breeze route) */

Route::middleware(['auth', 'verified', 'role:vendor'])
    
    ->group(function () {
        Route::get('dashboard', [VendorController::class, 'dashboard'])->name('dashboard');
        Route::get('profile', [VendorProfileController::class, 'index'])->name('profile');
        Route::put('profile', [VendorProfileController::class, 'updateProfile'])->name('profile.update');
        Route::post('profile', [VendorProfileController::class, 'updatePassword'])->name('profile.update.password');
    });

/** Vendor's address routes */

Route::get('vendor/dashboard/address/index', [VendorAddressController::class, 'address'])->name('vendor.address');
Route::get('vendor/dashboard/address/create', [VendorAddressController::class, 'create'])->name('vendor.address.create');
Route::post('vendor/dashboard/address', [VendorAddressController::class, 'store'])->name('vendor.address.store');
Route::get('vendor/dashboard/address/{id}/edit', [VendorAddressController::class, 'edit'])->name('vendor.address.edit');
Route::put('vendor/dashboard/address/{id}', [VendorAddressController::class, 'update'])->name('vendor.address.update');
Route::delete('vendor/dashboard/address/{id}', [VendorAddressController::class, 'destroy'])->name('vendor.address.destroy');

Snapey's avatar

so im guessing you added a prefix and namespace where you load the vendor file?

You dont need to add vendor. to any of these route names - as you did with profile

LaravelFan's avatar

@Snapey Yes, this is inside the RouteServiceProvider:


<?php

namespace App\Providers;

use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * The path to your application's "home" route.
     *
     * Typically, users are redirected here after authentication.
     *
     * @var string
     */
    public const HOME = '/user/dashboard';

    /**
     * Define your route model bindings, pattern filters, and other route configuration.
     */
    public function boot(): void
    {
        RateLimiter::for('api', function (Request $request) {
            return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
        });

        $this->routes(function () {
            Route::middleware('api')
                ->prefix('api')
                ->group(base_path('routes/api.php'));

            Route::middleware('web')
                ->group(base_path('routes/web.php'));

            Route::middleware(['web', 'auth', 'role:admin'])
                ->prefix('admin')
                ->as('admin.')
                ->group(base_path('routes/admin.php'));

            Route::middleware(['web', 'auth', 'role:vendor'])
                ->prefix('vendor')
                ->as('vendor.')
                ->group(base_path('routes/vendor.php'));

                Route::middleware(['web', 'auth', 'role:user'])
                ->prefix('user')
                ->as('user.')
                ->group(base_path('routes/user.php'));
        });
    }
}


LaravelFan's avatar

@snapey This is the VendorAddressController now:


<?php

namespace App\Http\Controllers;

use App\Models\VendorAddress;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;


class VendorAddressController extends Controller
{
    // This will return the address page
    public function address()
    {
        $addresses = VendorAddress::where('user_id', Auth::user()->id)->get();
        return view('vendor.dashboard.address.index', compact('addresses'));
    }

    // This will return the create page
    public function create()
    {
        return view('vendor.dashboard.address.create');
    }

    public function store(Request $request)
    {
        // This adds validation to the user input fields
        $request->validate([
            'name' => ['required', 'max:200'],
            'email' => ['required', 'max:200', 'email'],
            'phone' => ['required', 'max:200'],
            'country' => ['required', 'max:200'],
            'state' => ['required', 'max:200'],
            'city' => ['required', 'max:200'],
            'zip' => ['required', 'max:200'],
            'address' => ['required', 'max:200'],

        ]);

        // This stores the user input into the database
        $address = new VendorAddress();
        $address->user_id = Auth::user()->id;
        $address->name = $request->name;
        $address->email = $request->email;
        $address->phone = $request->phone;
        $address->country = $request->country;
        $address->state = $request->state;
        $address->city = $request->city;
        $address->zip = $request->zip;
        $address->address = $request->address;
        $address->save();

        // This displays the toast message 
        toastr('Updated Successfully!')->success('Address successfully added!');
        return redirect()->route('vendor.address');
    }

    // This will update an existing address

    public function edit(string $id)
    {
        $address = VendorAddress::findOrFail($id);
        return view('vendor.dashboard.address.edit', compact('address'));
    }

    public function update(Request $request, string $id)
    {
        $request->validate([
            'name' => ['required', 'max:200'],
            'email' => ['required', 'max:200', 'email'],
            'phone' => ['required', 'max:200'],
            'country' => ['required', 'max:200'],
            'state' => ['required', 'max:200'],
            'city' => ['required', 'max:200'],
            'zip' => ['required', 'max:200'],
            'address' => ['required'],
        ]);

        $address = Vendoraddress::findOrFail($id);
        $address->user_id = Auth::user()->id;
        $address->name = $request->name;
        $address->email = $request->email;
        $address->phone = $request->phone;
        $address->country = $request->country;
        $address->state = $request->state;
        $address->city = $request->city;
        $address->zip = $request->zip;
        $address->address = $request->address;
        $address->save();

        toastr('Updated Successfully!', 'success', 'Success')->success('Updated Successfully!');

        return redirect()->route('vendor.address');
    }

    // This will delete an address

    public function destroy(string $id)
    {
        $address = VendorAddress::findOrFail($id);
        $address->delete();

        return response(['status' => 'success', 'message' => 'Deleted Successfully!']);
    }
}


This is the Vendor.php routes file:


<?php

use App\Http\Controllers\VendorController;
use App\Http\Controllers\VendorProfileController;
use App\Http\Controllers\VendorAddressController;
use Illuminate\Support\Facades\Route;


/** This updates the vendor's username, email and password (copied from Laravel Breeze route) */

Route::middleware(['auth', 'verified', 'role:vendor'])
    
    ->group(function () {
        Route::get('dashboard', [VendorController::class, 'dashboard'])->name('dashboard');
        Route::get('profile', [VendorProfileController::class, 'index'])->name('profile');
        Route::put('profile', [VendorProfileController::class, 'updateProfile'])->name('profile.update');
        Route::post('profile', [VendorProfileController::class, 'updatePassword'])->name('profile.update.password');
    });

/** Vendor's address routes */

Route::get('vendor', [VendorAddressController::class, 'address'])->name('vendor.address');
Route::get('vendor', [VendorAddressController::class, 'create'])->name('vendor.address.create');
Route::post('vendor', [VendorAddressController::class, 'store'])->name('vendor.address.store');
Route::get('vendor/dashboard/address/{id}/edit', [VendorAddressController::class, 'edit'])->name('vendor.address.edit');
Route::put('vendor/dashboard/address/{id}', [VendorAddressController::class, 'update'])->name('vendor.address.update');
Route::delete('vendor/dashboard/address/{id}', [VendorAddressController::class, 'destroy'])->name('vendor.address.destroy');

Snapey's avatar

Why do you keep showing the controller. It has absolutely nothing to do with routing.

Are you still stuck on the idea that views have to be named the same as routes?

But I'm wondering, why does this work

<li><a href="{{ route('vendor.profile') }}"><i class="far fa-user"></i> My Profile</a></li> 

because your route name does NOT include 'vendor'

Route::get('profile', [VendorProfileController::class, 'index'])->name('profile');

if you don't want to reference routes as vendor.vendor.something, take it out of the routes


Route::get('dashboard/address/index', [VendorAddressController::class, 'address'])->name('address');
Route::get('dashboard/address/create', [VendorAddressController::class, 'create'])->name('address.create');
Route::post('dashboard/address', [VendorAddressController::class, 'store'])->name('address.store');
Route::get('dashboard/address/{id}/edit', [VendorAddressController::class, 'edit'])->name('address.edit');
Route::put('dashboard/address/{id}', [VendorAddressController::class, 'update'])->name(address.update');
Route::delete('dashboard/address/{id}', [VendorAddressController::class, 'destroy'])->name('address.destroy');


LaravelFan's avatar

@Snapey "Are you still stuck on the idea that views have to be named the same as routes?" Wow, SOMETHING just lit up in my mind. I*ll work on it. Many thanks indeed.

LaravelFan's avatar

@Snapey This is how I did it now:


<?php

use App\Http\Controllers\VendorController;
use App\Http\Controllers\VendorProfileController;
use App\Http\Controllers\VendorAddressController;
use Illuminate\Support\Facades\Route;


/** This updates the vendor's username, email and password (copied from Laravel Breeze route) */

Route::middleware(['auth', 'verified', 'role:vendor'])
    
    ->group(function () {
        Route::get('dashboard', [VendorController::class, 'dashboard'])->name('dashboard');
        Route::get('profile', [VendorProfileController::class, 'index'])->name('profile');
        Route::put('profile', [VendorProfileController::class, 'updateProfile'])->name('profile.update');
        Route::post('profile', [VendorProfileController::class, 'updatePassword'])->name('profile.update.password');
    });

/** Vendor's address routes */

Route::get('address', [VendorAddressController::class, 'address'])->name('address');
Route::get('vendor/dashboard/address/create', [VendorAddressController::class, 'create'])->name('vendor.address.create');
Route::post('vendor/dashboard/address', [VendorAddressController::class, 'store'])->name('vendor.address.store');
Route::get('vendor/dashboard/address/{id}/edit', [VendorAddressController::class, 'edit'])->name('vendor.address.edit');
Route::put('vendor/dashboard/address/{id}', [VendorAddressController::class, 'update'])->name('vendor.address.update');
Route::delete('vendor/dashboard/address/{id}', [VendorAddressController::class, 'destroy'])->name('vendor.address.destroy');


But I'm getting Route [address] not defined.

This is the user routes files and everything works fine:


<?php

use App\Http\Controllers\UserProfileController;
use App\Http\Controllers\UserAddressController;
use App\Http\Controllers\UserDashboardController;
use Illuminate\Support\Facades\Route;


/** Laravel Breeze routes that update the User's username, email and password */
Route::middleware(['auth', 'verified', 'role:user'])
    ->group(function () {
        Route::get('dashboard', [UserDashboardController::class, 'dashboard'])->name('dashboard');
        Route::get('profile', [UserProfileController::class, 'index'])->name('profile');
        Route::get('address', [UserAddressController::class, 'address'])->name('address');
        Route::put('profile', [UserProfileController::class, 'updateProfile'])->name('profile.update');
        Route::post('profile', [UserProfileController::class, 'updatePassword'])->name('profile.update.password');
    });

/** User Address route */
Route::get('user/dashboard/create', [UserAddressController::class, 'create'])->name('address.create');
Route::post('user/dashboard/address', [UserAddressController::class, 'store'])->name('address.store');
Route::get('user/dashboard/address/{id}/edit', [UserAddressController::class, 'edit'])->name('address.edit');
Route::put('user/dashboard/address/{id}', [UserAddressController::class, 'update'])->name('address.update');
Route::delete('user/dashboard/address/{id}', [UserAddressController::class, 'destroy'])->name('address.destroy');


LaravelFan's avatar

That finally did it:


<?php

use App\Http\Controllers\VendorProfileController;
use App\Http\Controllers\VendorAddressController;
use App\Http\Controllers\VendorController;

use Illuminate\Support\Facades\Route;


/** Laravel Breeze routes that update the User's username, email and password */
Route::middleware(['auth', 'verified', 'role:vendor'])
    ->group(function () {
        Route::get('dashboard', [VendorController::class, 'dashboard'])->name('dashboard');
        Route::get('profile', [VendorProfileController::class, 'index'])->name('profile');
        Route::get('address', [VendorAddressController::class, 'address'])->name('address');
        Route::put('profile', [VendorProfileController::class, 'updateProfile'])->name('profile.update');
        Route::post('profile', [VendorProfileController::class, 'updatePassword'])->name('profile.update.password');
    });

/** User Address route */
Route::get('vendor/dashboard/create', [VendorAddressController::class, 'create'])->name('address.create');
Route::post('vendor/dashboard/address', [VendorAddressController::class, 'store'])->name('address.store');
Route::get('vendor/dashboard/address/{id}/edit', [VendorAddressController::class, 'edit'])->name('address.edit');
Route::put('vendor/dashboard/address/{id}', [VendorAddressController::class, 'update'])->name('address.update');
Route::delete('vendor/dashboard/address/{id}', [VendorAddressController::class, 'destroy'])->name('address.destroy');

LaravelFan's avatar

Is it because by moving the 'address' route inside the middleware group, it took precedence over the more specific routes defined after it?

LaravelFan's avatar

Another issue, I'm getting: The GET method is not supported for route vendor/vendor/dashboard/address/2. Supported methods: PUT. The relevant route in question is:


Route::delete('vendor/dashboard/address/{id}', [VendorAddressController::class, 'destroy'])->name('address.destroy');

In the user's dashboard, I'm able to delete an address in the user's dashboard without an error message showing.

martinbean's avatar

@Mamunsson Because you don’t have any routes with that URI that respond to GET requests.

These error messages are telling you exactly what’s wrong. You need to read them.

martinbean's avatar

@Mamunsson You‘re making a GET request to vendor/vendor/dashboard/address/2. But you don’t have any Route::get definitions with that URI. But you do have a Route::put definition with that URI, hence you getting the “Supported methods: PUT” error.

If you want resource routes, then why not use actual resource routes instead of trying to register them all individually? 🤷‍♂️

Route::resource('addresses', AddressController::class);

Done. It will register multiple routes, and it will use the correct naming conventions for everything. Your naming is all over the place.

Snapey's avatar

what does the view look like where you try and delete?

LaravelFan's avatar

@Snapey In the address bar I see: http://127.0.0.1:8000/vendor/vendor/dashboard/address/2

The message is: The GET method is not supported for route vendor/vendor/dashboard/address/2. Supported methods: PUT, DELETE.

´´´´´´

It says public  /  index .php   : 51 require_once

´´´´´´

´´´´´´

|

| Composer provides a convenient, automatically generated class loader for

| this application. We just need to utilize it! We'll simply require it

| into the script here so we don't need to manually load our classes.

|

*/

require DIR.'/../vendor/autoload.php';

/*

|--------------------------------------------------------------------------

| Run The Application

|--------------------------------------------------------------------------

|

| Once we have the application, we can handle the incoming request using

| the application's HTTP kernel. Then, we will send the response back

| to this client's browser, allowing them to enjoy our application.

|

*/

$app = require_once DIR.'/../bootstrap/app.php';

$kernel = $app->make(Kernel::class);

$response = $kernel->handle(

$request = Request::capture()

)->send();

$kernel->terminate($request, $response);

´´´´´´

Snapey's avatar

@Mamunsson please try and pay attention

I want to see the blade file where you request deletion of file

Put your code between three backticks ``` on their own line

LaravelFan's avatar

@Snapey

Hi, Sorry for missing. This is the blade file:


@extends('vendor.dashboard.layouts.master')
@section('content')
    <section id="wsus__dashboard">
        <div class="container-fluid">
            @include('vendor.dashboard.layouts.sidebar')
            <div class="row">
                <div class="col-xl-9 col-xxl-10 col-lg-9 ms-auto">
                    <div class="dashboard_content">
                        <h3><i class="fal fa-gift-card"></i> address</h3>
                        <div class="wsus__dashboard_add">
                            <div class="row">
                                @foreach ($addresses as $address)
                                    <div class="col-xl-6">
                                        <div class="wsus__dash_add_single">
                                            <h4>Billing Address</h4>
                                            <ul>
                                                <li><span>name :</span> {{ $address->name }}</li>
                                                <li><span>Phone :</span> {{ $address->phone }}</li>
                                                <li><span>email :</span> {{ $address->email }}</li>
                                                <li><span>country :</span> {{ $address->country }}</li>
                                                <li><span>city :</span> {{ $address->state }}</li>
                                                <li><span>zip code :</span> {{ $address->city }}</li>
                                                <li><span>company :</span> {{ $address->zip }}</li>
                                                <li><span>address :</span> {{ $address->address }}</li>
                                            </ul>
                                            <div class="wsus__address_btn">
                                                <a href="{{ route('vendor.address.edit', ['id' => $address->id]) }}"
                                                    class="edit"><i class="fal fa-edit"></i> edit</a>
                                                <a href="{{ route('vendor.address.destroy', $address->id) }}"
                                                    class="del delete-item"><i class="fal fa-trash-alt"></i> delete</a>
                                            </div>
                                        </div>
                                    </div>
                                @endforeach
                                <div class="col-12">
                                    <a href="{{ route('vendor.address.create') }}" class="add_address_btn common_btn"><i
                                            class="far fa-plus"></i>
                                        add new address</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection

Snapey's avatar

for delete you must use a form, otherwise a get is issued

not

 <a href="{{ route('vendor.address.destroy', $address->id) }}   class="del delete-item"><i class="fal fa-trash-alt"></i> delete</a>
                            

instead

<form method="post" action="{{ route('vendor.address.destroy', $address->id) }}"> 
@csrf @method("delete")
<button type="submit"  class="del delete-item"><i class="fal fa-trash-alt"></i> delete</button>
</form>
LaravelFan's avatar

@Snapey Hi, This does work indeed. But I've a question: Why does this also work fine without having to add form post method? Below is the user's dashboard:

@extends('user.dashboard.layouts.master')
@section('content')
    <section id="wsus__dashboard">
        <div class="container-fluid">
            @include('user.dashboard.layouts.sidebar')
            <div class="row">
                <div class="col-xl-9 col-xxl-10 col-lg-9 ms-auto">
                    <div class="dashboard_content">
                        <h3><i class="fal fa-gift-card"></i> address</h3>
                        <div class="wsus__dashboard_add">
                            <div class="row">
                                @foreach ($addresses as $address)
                                    <div class="col-xl-6">
                                        <div class="wsus__dash_add_single">
                                            <h4>Billing Address</h4>
                                            <ul>
                                                <li><span>name :</span> {{ $address->name }}</li>
                                                <li><span>Phone :</span> {{ $address->phone }}</li>
                                                <li><span>email :</span> {{ $address->email }}</li>
                                                <li><span>country :</span> {{ $address->country }}</li>
                                                <li><span>city :</span> {{ $address->state }}</li>
                                                <li><span>zip code :</span> {{ $address->city }}</li>
                                                <li><span>company :</span> {{ $address->zip }}</li>
                                                <li><span>address :</span> {{ $address->address }}</li>
                                            </ul>
                                            <div class="wsus__address_btn">
                                                <a href="{{ route('user.address.edit', ['id' => $address->id]) }}"
                                                    class="edit"><i class="fal fa-edit"></i> edit</a>
                                                    <a href="{{route('user.address.destroy', $address->id)}}" class="del delete-item"><i class="fal fa-trash-alt"></i> delete</a>
                                            </div>
                                        </div>
                                    </div>
                                @endforeach
                                <div class="col-12">
                                    <a href="{{ route('user.address.create') }}" class="add_address_btn common_btn"><i
                                            class="far fa-plus"></i>
                                        add new address</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection

martinbean's avatar

@Mamunsson You keep being told the same thing over and over again.

Your delete “button” is just in a standard <a> tag:

<a href="{{route('user.address.destroy', $address->id)}}" class="del delete-item"><i class="fal fa-trash-alt"></i> delete</a>

This is going to perform a GET request. Not a DELETE request. Hence “GET method is not supported” error message.

LaravelFan's avatar

@martinbean I'm not doubting your input at all. But, I'm telling you what I'm seeing. This is inside the user's dashboard sidebar panel:


<div class="wsus__address_btn">
                                                <a href="{{ route('user.address.edit', ['id' => $address->id]) }}"
                                                    class="edit"><i class="fal fa-edit"></i> edit</a>
                                                    <a href="{{route('user.address.destroy', $address->id)}}" class="del delete-item"><i class="fal fa-trash-alt"></i> delete</a>
                                            </div>

So, to give it a test, I entered my address details in the user's dashboard and it was stored in the database. When I deleted the address in the user's (not the vendor's dashboard) dashboard, it was deleted! Gone! This is why I'm wondering.

Snapey's avatar
Snapey
Best Answer
Level 122

@Mamunsson

The delete link on the address page might 'work' if you have described the route as a GET route.

You should never do a delete from a simple link tag. Browsers can (and do) prefetch links without the user knowing, leading to unexpected record deletion.

1 like
LaravelFan's avatar

@Snapey

This is the relevant route for the user


Route::delete('user/dashboard/address/{id}', [UserAddressController::class, 'destroy'])->name('address.destroy');

And this is the relevant route for the vendor:


Route::delete('vendor/dashboard/address/{id}', [VendorAddressController::class, 'destroy'])->name('address.destroy');

Both use the delete method except that the use's address can be deleted but the vendor's cannot.

Since you write that I should never do a delete from a simple link tag, I shall use the code you provided and I'm very grateful for the clear explanation.

Please or to participate in this conversation.