简体   繁体   English

在RouteCollection.php第219行中的Laravel 5.2 MethodNotAllowedHttpException

[英]Laravel 5.2 MethodNotAllowedHttpException in RouteCollection.php line 219

First my error was Class Input not found so i added 首先我的错误是没有找到类输入,所以我添加了

'Input' => Illuminate\\Support\\Facades\\Input::class, 'input'=> Illuminate \\ Support \\ Facades \\ Input :: class,

in aliases array 在别名数组中

Now when i submit my form it gives this error 现在,当我提交表单时,它会出现此错误

ERROR: MethodNotAllowedHttpException in RouteCollection.php line 219: 错误:RouteCollection.php第219行中的MethodNotAllowedHttpException:

Routes.php routes.php文件

Route::post('add', function () {
    $name = Input::get('name');
    if(DB::table('projects')->whereName($name)->first() != NULL) return 'already exist';
    DB::table('projects')->insert(array('name'=>'$name'));
    return Redirect::to('/add'); 
});

welcome.blade.php : welcome.blade.php:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Laravel Learning</title>
</head>
    <body>
            {!! Form::open(array('url' => 'add')) !!}
                {!! Form::text('name', 'Your Name...') !!}
                {!! Form::submit('Click Me!') !!}
            {!! Form::close() !!}   
    </body>
</html>

Error Snap: 错误捕捉: 在此输入图像描述

Try to bring into practice of not using the routes.php to directly executing functions. 尝试不使用routes.php直接执行函数。 meaning, the function used in the routes is suposed to be in a controller, maybe that is why laravel 5.1 isnt allowing you to perform the task. 意思是,路由中使用的函数是在控制器中,也许这就是laravel 5.1不允许你执行任务的原因。

to give you a better understanding of the workflow 让您更好地了解工作流程

routes.php -> routes.php - >

Route::resource('projects', 'projectController');

welcome.blade.php -> welcome.blade.php - >

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Laravel Learning</title>
</head>
<body>
        {!! Form::open(array('url' => 'projects')) !!}
            {!! Form::text('name', 'Your Name...') !!}
            {!! Form::submit('Click Me!') !!}
        {!! Form::close() !!}   
</body>
</html>

Then, go to your cmd, browse to your project folder, and fire up the command 然后,转到cmd,浏览到项目文件夹,然后启动命令

php artisan make:controller projectController

Here, the relevant functions you need will be automatically created for you, for ease of use of the functions, cool huh... 在这里,您将自动为您创建所需的相关功能,以便于使用功能,很酷......

Now write your add logic into the create function. 现在将您的添加逻辑写入create函数。

public function store()
{
  Project::create(Request::all());
  //here you can write your return redirect(''); 
}

Also make sure you create a model. 还要确保创建模型。 for example 例如

run command 运行命令

php artisan make:model Project

inside the Project model -> 在项目模型中 - >

protected $fillable = [
 'name'
];

the purpose of using this fillable array is for security purposes to avoid mass assignment vulnerability. 使用此可填充数组的目的是出于安全目的,以避免质量分配漏洞。

hope this helps you. 希望这能帮助你。 feel free to ask questions 随意问的问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel 5.2:RouteCollection.php 第 219 行中的 MethodNotAllowedHttpException - Laravel 5.2 : MethodNotAllowedHttpException in RouteCollection.php line 219 RouteCollection.php 第 219 行中的 Laravel 5 MethodNotAllowedHttpException - Laravel 5 MethodNotAllowedHttpException in RouteCollection.php line 219 Laravel 5:RouteCollection.php第219行中的MethodNotAllowedHttpException - Laravel 5: MethodNotAllowedHttpException in RouteCollection.php line 219 Laravel 5在RouteCollection.php第219行中的MethodNotAllowedHttpException: - Laravel 5 MethodNotAllowedHttpException in RouteCollection.php line 219: MethodNotAllowedHttpException in RouteCollection.php line 219 Error Lravel 5.2 - MethodNotAllowedHttpException in RouteCollection.php line 219 Error Lravel 5.2 Laravel API 中 RouteCollection.php 第 219 行中的 MethodNotAllowedHttpException - MethodNotAllowedHttpException in RouteCollection.php line 219 in laravel API's Laravel 错误:RouteCollection.php 第 219 行中的 MethodNotAllowedHttpException - Laravel error: MethodNotAllowedHttpException in RouteCollection.php line 219 在Laravel中在RouteCollection.php第219行中获取MethodNotAllowedHttpException - Getting MethodNotAllowedHttpException in RouteCollection.php line 219: on laravel RouteCollection.php 219行中的MethodNotAllowedHttpException错误laravel: - MethodNotAllowedHttpException in RouteCollection.php line 219 error laravel: Laravel 5.1.26:RouteCollection.php第219行中的MethodNotAllowedHttpException - Laravel 5.1.26 : MethodNotAllowedHttpException in RouteCollection.php line 219
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM