Search code examples
phprouteslaravel-9

laravel makes urls that doesn´t exist ,how can i fix?


when i am in a specific page ('create.blade.php') with the url (/venta/create) the Urls in the navbar works wrongs

for example when i click the link to products it sends me to this url=

http://localhost:8080/example-app/public/venta/producto

venta/producto doesn´t existis ,its just /producto,the same things happen with all links clicked in page /venta/create
another example= http://localhost:8080/example-app/public/venta/cliente the link should be http://localhost:8080/example-app/public/cliente without venta/

These are all my routes in web.php

Route::get('/home',[HomeController::class,'index'])->name('home') ;

Route::get('/producto',[ProductoController::class,'index'])->name('producto') ;
Route::post('/producto',[ProductoController::class,'store']);
Route::put('producto/{id}',[ProductoController::class,'update']);
Route::delete('producto/{id}',[ProductoController::class,'destroy']);



Route::get('cliente',[ClienteController::class,'index'])->name('cliente') ;
Route::post('cliente',[ClienteController::class,'store']);
Route::put('cliente/{id}',[ClienteController::class,'update']);
Route::delete('cliente/{id}',[ClienteController::class,'destroy']);
Route::post('cliente/telefono',[ClienteController::class,'getTelefono']);

Route::get('venta',[VentaController::class,'index'])->name('venta');
Route::get('/venta/create',[VentaController::class,'create']);
Route::post('venta',[VentaController::class,'store']);
Route::put('venta/{id}',[VentaController::class,'update']);
Route::delete('venta/{id}',[VentaController::class,'destroy']);


Route::get('/vendedor',[VendedorController::class,'index'])->name('vendedor');
Route::post('vendedor',[VendedorController::class,'store']);
Route::put('vendedor/{id}',[VendedorController::class,'update']);
Route::delete('vendedor/{id}',[VendedorController::class,'destroy']);
Route::post('vendedor/cantidad',[VendedorController::class,'getVentas']);```

 if I am on any page except the previous one mentioned and click in the links of navbar ,
urls works good.

--Error message--

The GET method is not supported for route venta/cliente


¡route venta/cliente doesn´t exists,its just /cliente!

Solution

  • app -> config-> app.php

    'url' => env('APP_URL', 'your base url here'),
    

    or at .env file

    APP_URL= your base url 
    

    in your case base url example

    http://localhost:8080/example-app
    

    And verify you used url like given below

    {{url('/products')}}