Home > Blockchain >  Error 404 with Laravel API in store route
Error 404 with Laravel API in store route

Time:03-17

I am working with Laravel version 8. I have my route like this:

Route::post('/user', 'App\Http\Controllers\api\UserController@store');

I have my form like this:

<form method="POST" action="{{ url('api/user/store') }}">
        @csrf

        <div >
           <label for="rut" >{{ __('Rut') }}</label>

              <div >
                  <input id="rut" type="text"  name="rut" value="{{ old('rut') }}" required autocomplete="rut" autofocus>

                   @error('name')
                      <span  role="alert">
                        <strong>{{ $message }}</strong>
                      </span>
                  @enderror
             </div>
         </div>

I ahve a controller in this path: App\Http\Controllers\api\UserController

My controller:

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class UserController extends Controller
{

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(Request $request)
{
    echo 1;
    die();
}

}

My route list:

routes

When I click submit it display error 404... the route was not found. what could it be?

CodePudding user response:

Please try to change form's action to '/user', for verifying your right rules you can check it with artisan command php artisan route:list

CodePudding user response:

You can try changing this in your {{ url('api/user/store') }}

{{ route('user.store', 'user_store')}}

CodePudding user response:

change action="{{ url('api/user/store') }}" to action="{{ url('api/user') }}"

  • Related