简体   繁体   English

Laravel 7“未找到‘表格’类”

[英]Laravel 7 "Class 'Form' not found"

I went to work Laravel!我去上班了 Laravel! when I typed in my code当我输入我的代码时

{{ Form::token()   }}

I got the message "Class 'Form' not found"!我收到消息“找不到‘表格’类”! I went to google to investigate this error but the results are all for laravel versions 4,5,6 nowhere for version 7 And that confuses me a bit I can't orient myself!我去谷歌调查这个错误,但结果都是针对版本 4、5、6 的 laravel 版本 7 无处可去 这让我有点困惑,我无法定位自己! Please Help me!请帮我!

create.blade.php创建.blade.php


@section ('content')
    <form action="{{ URL::route('account-create-post') }}" method="post">
            <input type="submit" value="Create Account">
            {{ Form::token() }}
    </form>
@stop 

Web.php网页.php

Route::group(array('brefore' => 'guest'), function() {

    Route::group(array('brefore' => 'csrf'), function(){

        Route::post('/account/create',array(
            'as' => 'account-create-post',
            'uses' => 'AccountController@postcreate'
        ));

    });
}

One of the reason that you may get the error Class 'Form' not found is that you have not been registered the form on your config/app.php.您可能会收到错误 Class 'Form' not found 的原因之一是您尚未在 config/app.php 上注册该表单。 You should register it if you have not done it yet.如果你还没有注册,你应该注册它。 here is an example:这是一个例子:

'aliases' => [
...
// others
  'Form' => Collective\Html\FormFacade::class,
  'Html' => Collective\Html\HtmlFacade::class,
],

If you have not installed yet install it and register it.如果您还没有安装,请安装并注册。 you can add csrf token with other methods if you want.如果需要,您可以使用其他方法添加 csrf 令牌。 You can use blade for this like this你可以像这样使用刀片

 <form action="{{ URL::route('account-create-post') }}" method="post">
            <input type="submit" value="Create Account">
            @csrf
    </form>

If you need just token, you can get it with csrf_token() like this:如果你只需要令牌,你可以像这样使用 csrf_token() 获得它:

<input type="hidden" name="_token" value="{{csrf_token()}}">

I got the message "Class 'Form' not found"!我收到消息“找不到‘表格’类”! I went to google to investigate this error but the results are all for laravel versions 4,5,6 nowhere for version 7 And that confuses me a bit I can't orient myself!我去谷歌调查这个错误,但结果都是针对版本 4、5、6 的 laravel 版本 7 无处可去 这让我有点困惑,我无法定位自己!

No. You can only use the Form class maximum Laravel version 4.不可以。您只能使用最大 Laravel 版本 4 的Form类。

The Form and HTML helpers have been deprecated since Laravel 5 .从 Laravel 5 开始不推荐使用FormHTML助手 However, there are community-driven replacements such as those maintained by the Laravel Collective .但是,也有社区驱动的替代品,例如Laravel Collective维护的替代品

Anytime you define an HTML form in your application, you should include a hidden CSRF token field in the form so that the CSRF protection middleware can validate the request.任何时候在应用程序中定义 HTML 表单时,都应该在表单中包含一个隐藏的 CSRF 令牌字段,以便 CSRF 保护中间件可以验证请求。 You may use the @csrf Blade directive to generate the token field:您可以使用@csrf Blade 指令生成令牌字段:

<form action="{{ route('account-create-post') }}" method="POST">
    @csrf

    ...
</form>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM