dimanche 8 novembre 2015

Laravel 5.1: MethodNotAllowedHttpException

When i am making a request from a form in Laravel and i want to store it in a database it throw this error: MethodNotAllowedHttpException. I cannot understand what i have done wrong so can you please help me?

Here is my form:

<form method="POST" action="/admin/ajax/edit">
        {{ csrf_field() }}
        <div class="textEdit">
            <div class="marginizer"> 
                <textarea id="edit" name="edit"></textarea>
            </div>
        </div>
        <input type="submit">
    </form>

Here is my routes file:

Route::get('admin/dashboard', 'Dashboard@index');
Route::get('admin/dashboard/{id}', 'Dashboard@show');
Route::get('admin/dashboard/edit/{site}', 'Edit@edit');
Route::get('admin', 'Dashboard@index');

// Register and Login routes...
Route::get('admin/login', 'Login@index');
Route::get('admin/register', 'Register@index');

// Authentication routes...
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

// Registration routes...
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');

// Ajax routes
Route::post('admin/ajax/edit', 'EditAjax@store');

// UI routes
Route::get('/', 'ThemeLoader@index');
Route::get('/{site}', 'ThemeLoader@show');

Route::get('migrate', 'migrate@migrate');
Route::get('migrate/refresh', 'migrate@refresh');

And here is my controller which handles the request:

public function store(Request $request) {

    $content = new Content;

    $content->site = 'Index';
    $content->block = 1;
    $content->content = $request->input('edit');
    $content->active = 1;

    $content->save();
}

It actually stores the data in the database correctly but it continues to come up with error.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire