Edit: I think this problem is due to not setting up apache properly, these two links helped me.
Solution:
http://laravel.io/forum/06-11-2014-not-found-but-route-exists
End Edit
I'm following the Laravel 5.2 quickstart guide. https://laravel.com/docs/5.2/quickstart
I'm running ubuntu 14.04.2
The website runs initially, but then when I click on the add Task button I run into a 404 Not Found error.
As per the guide I run the following commands to setup the complete quickstart project.
git clone https://github.com/laravel/quickstart-basic quickstart
cd quickstart
composer install
php artisan migrate
Additionally I run the following commands because I'm on an ubuntu server:
sudo chown -R www-data.www-data quickstart
sudo chmod -R 755 quickstart
sudo chmod 777 quickstart/storage
The routes.php file looks like:
<?php
use App\Task;
use Illuminate\Http\Request;
Route::group(['middleware' => ['web']], function () {
//
Route::get('/', function () {
$tasks = Task::orderBy('created_at', 'asc')->get();
return view('tasks', [
'tasks' => $tasks
]);
});
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('/');
});
//
Route::delete('/task/{task}', function (Task $task) {
$task->delete();
return redirect('/');
});
});
I tried changing some code in the resources/view/tasks.blade.php from:
<!-- New Task Form -->
<form action="/task" method="POST" class="form-horizontal">
To the location of the actual public folder of the laravel project :
<!-- New Task Form -->
<form action="/learninglaravel/laraquickstart/quickstart/public/task" method="POST" class="form-horizontal">
So my problem is only when I press the button I get a 404 Error
//***** Edit:
I have tried having editing the post route but that doesn't fix the problem.
Route::post('/learninglaravel/laraquickstart/quickstart/public/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('/');
});
The error is:
Not Found
The requested URL /learninglaravel/laraquickstart/quickstart/public/task was not found on this server.
Instead of:
Not Found
The requested URL /task was not found on this server.
I did what you suggested James and you were right, it makes the URL change to
/learninglaravel/laraquickstart/quickstart/public/task
but I still get the error of page not found. The only difference is the error message changed from the bellow error to the above. (I also tried manually changing both the url in the route.php file and the tasks.blade.php to reflect the same url. So the above URL would be both in the routes.php and the tasks.blade.php
I'm running on an ubuntu AWS server maybe I made a mistake on that end? I think the quickstart tutorial was written for homestead as I ran into problems with the database.(I just had to manually create one. The guide never specified that. I think it might be pre-configured in homestead to automatically use a database)
Cheers