I am using Laravel 5 and started the quickstart from the Laravel website. If i used the post function that is in the code it redirects to localhost/LOCATION instead of localhost/PROJECT/public/LOCATION.
It might be something in my config but i can't figure out what it is.
here is the code from my router it appears to be a problem in the post task function.
<?php
use App\Task;
use Illuminate\Http\Request;
Route::group(['middleware' => ['web']], function () {
/**
* Show Task Dashboard
*/
Route::get('/', function () {
return view('tasks', [
'tasks' => Task::orderBy('created_at', 'asc')->get()
]);
});
/**
* Add 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 Task
*/
Route::delete('/task/{id}', function ($id) {
Task::findOrFail($id)->delete();
return redirect('/');
});
});
With this code I post to the route
<form action="/task" method="POST" class="form-horizontal">
{{ csrf_field() }}
<!-- Task Name -->
<div class="form-group">
<label for="task-name" class="col-sm-3 control-label">Task</label>
<div class="col-sm-6">
<input type="text" name="name" id="task-name" class="form-control" value="{{ old('task') }}">
</div>
</div>
<!-- Add Task Button -->
<div class="form-group">
<div class="col-sm-offset-3 col-sm-6">
<button type="submit" class="btn btn-default">
<i class="fa fa-btn fa-plus"></i>Add Task
</button>
</div>
</div>
</form>
UPDATE If I change my form action to "/quickstart/public/task" it works but /task should redirect to it automatically in laravel if i remember correctly