mardi 24 novembre 2015

laravel 5 can GET routes, but not POST

going through the tutorial on Laravel 5 here: http://ift.tt/1O628Bo

Now, when it comes to trying to post form data to /task I get an error...

Not Found
The requested URL /task was not found on this server.

Worse, if I set up a route to GET /task and echo out something simple - this works. Is there something I am missing for a POST, please?

Here is my full route file:

<?php

use App\Task;
use Illuminate\Http\Request;

/**
 * Display All Tasks
 */
Route::get('/', function () {
    $tasks = Task::orderBy('created_at', 'asc')->get();

    return view('tasks', [
        'tasks' => $tasks
    ]);
});

/**
 * Add A New Task
 */
Route::post('/task', function (Request $request) {
    $validator = Validator::make($request->all(), [
        'name' => 'required|max:255',
    ]);

    if ($validator->fails()) {
        //return redirect('/')->withInput()->withErrors($validator);
    }

    $task = new Task;
    $task->name = $request->name;
    $task->save();

    //return redirect('/');
});

/**
 * Delete An Existing Task
 */
Route::delete('/task/{id}', function ($id) {
    Task::findOrFail($id)->delete();

    return redirect('/');
});


Route::get('/task', function() {
    echo 'ds';
});

Thanks folks.

DS



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire