Laravel 5.2快速入门指南给出了Not Found Error [英] Laravel 5.2 quickstart guide gives Not Found Error

查看:46
本文介绍了Laravel 5.2快速入门指南给出了Not Found Error的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这个问题是由于未正确设置apache引起的,这两个链接对我有所帮助.

解决方案:

http://laravel.io/forum/2014年6月11日-找不到路线但存在

https://laravel.com/docs/5.2/quickstart

我正在运行ubuntu 14.04.2

该网站最初运行,但是随后当我单击添加任务"按钮时我遇到404未找到错误.

按照指南,我运行以下命令来设置完整的快速入门项目.

  git clone https://github.com/laravel/quickstart-基本快速入门cd快速入门作曲家安装PHP的工匠迁移 

另外,由于我在ubuntu服务器上,所以我运行以下命令:

  sudo chown -R www-data.www-data快速入门sudo chmod -R 755快速入门sudo chmod 777快速入门/存储 

routes.php文件如下:

 <?php使用App \ Task;使用Illuminate \ Http \ Request;Route :: group(['middleware'=> ['web']],function(){//路线:: get('/',函数(){$ tasks = Task :: orderBy('created_at','asc')-> get();返回视图(任务",['tasks'=>$任务]);});Route :: post('/task',function(Request $ request){$ validator = Validator :: make($ request-> all(),['名称'=>'required | max:255',]);if($ validator-> fails()){返回重定向('/')-> withInput()-> withErrors($ validator);}$ task =新任务;$ task-> name = $ request-> name;$ task-> save();返回redirect('/');});//Route :: delete('/task/{task}',function(Task $ task){$ task-> delete();返回redirect('/');});}); 

我尝试从以下位置更改resources/view/tasks.blade.php中的一些代码:

 <!-新任务表->< form action ="/task" method ="POST" class ="form-horizo​​ntal"> 

到laravel项目的实际公用文件夹的位置:

 <!-新任务表->< form action ="/learninglaravel/laraquickstart/quickstart/public/task" method ="POST" class ="form-horizo​​ntal"> 

所以我的问题仅是当我按下按钮时出现404错误

//*****

我尝试编辑帖子路线,但这不能解决问题.

  Route :: post('/learninglaravel/laraquickstart/quickstart/public/task',函数(Request $ request){$ validator = Validator :: make($ request-> all(),['名称'=>'required | max:255',]);if($ validator-> fails()){返回重定向('/')-> withInput()-> withErrors($ validator);}$ task =新任务;$ task-> name = $ request-> name;$ task-> save();返回redirect('/');}); 

错误是:

 未找到在此服务器上找不到请求的URL/learninglaravel/laraquickstart/quickstart/public/task. 

代替:

 未找到在此服务器上找不到请求的URL/task. 

我按照你的建议做了詹姆斯,而你是对的,它使URL变为

/learninglaravel/laraquickstart/quickstart/public/task

但是我仍然收到找不到页面的错误.唯一的区别是错误消息从波纹管错误变为上述错误消息.(我还尝试手动更改route.php文件和task.blade.php中的网址,以反映相同的网址.因此,上述URL将同时在route.php和task.blade.php

我正在ubuntu AWS服务器上运行,也许这是我弄错了吗?我认为快速入门教程是在我遇到数据库问题时为宅基地编写的.(我只需要手动创建一个.指南从未指定.我认为它可能已在宅基地中预先配置为自动使用数据库)

欢呼

解决方案

将表单操作参数更改为

 /learninglaravel/laraquickstart/quickstart/public/task 

您将向

发出HTTP POST请求

  {scheme}://{domain}//learninglaravel/laraquickstart/quickstart/public/task 

因此laravel将寻找这条路线,显然找不到.

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

https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts

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

解决方案

When you change your form action parameter to

/learninglaravel/laraquickstart/quickstart/public/task

You are going to make HTTP POST request to

{scheme}://{domain}//learninglaravel/laraquickstart/quickstart/public/task

So laravel is going to look for this route and obviously it won't find it.

这篇关于Laravel 5.2快速入门指南给出了Not Found Error的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆