mercredi 31 octobre 2018

Laravel Route Always Goes to index

In my Laravel application, I store a new user via Ajax to the DB. The app always calls the index method. What's wrong?

When I remove the Route::post('/users', 'Admin\UserController@store'); route there is a 405 error. That's correct. But why doesn't it go to the store method?

Controller

<?php

class UserController extends Controller
{

    public function index()
    {
        return view('admin.user.index');
    }

    public function create()
    {
        //
    }

    public function store(UserCreateRequest $request)
    {
        $user = User::createFromRequest($request);

        return response()->json(["id" => $user->id]);
    }
}

Routes

Route::group(['prefix' => 'admin', 'as' => 'admin.', ], function () {
Route::get('/users/{user}', 'Admin\UserController@show')->name('users.show');
Route::post('/users', 'Admin\UserController@store');
Route::put('/users/{id}', 'Admin\UserController@updateFromDatatable');
Route::delete('/users/{id}', 'Admin\UserController@destroy');
Route::get('/users', 'Admin\UserController@index')->name('users.index');



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire