douyanti2808 2017-06-10 02:06
浏览 45
已采纳

Laravel应用程序不断返回MethodNotAllowdHttpException

I've just made an app in Laravel running on Semantic UI, and when I run the program, it displays a MethodNotAllowedHttpException error. I have the code for the routes as displayed:

<?php

Route::get('/', function () {
    return view('welcome');
});

Route::get('/view', [
    'uses' => 'ViewController@index',
    'as' => 'view'
 ]);

 Route::post('/login', [
    'uses' => 'Auth\LoginController@login',
    'as' => 'login'
 ]);

The blade file also includes the 'method' and 'action' functions, as well. ` @extends('layouts.app')

 @section('title')
    Login
 @endsection

 @section('content')
    @if(count($errors) > 0)
    <div class="ui bulleted list">
        @foreach($errors as $error)
            <div class="item">{{ $error }}</div>
        @endforeach
    </div>
@endif
<div class="ui middle aligned center aligned grid">
    <div class="column">
        <h2 class="ui teal header">
            <p>
                Log in to your account
            </p>
        </h2>
        <form class="ui large form" action="{{ route('login') }}" method="post">
            <div class="ui stacked segment">
                <div class="field">
                    <div class="ui left icon input">
                        <i class="user icon"></i>
                        <input type="text" id="email" name="email" placeholder="Enter your email">
                    </div>

                    <div class="ui left icon input">
                        <div class="ui left icon input">
                            <i class="lock"></i>
                            <input type="password" id="password" name="password" placeholder="Enter your password">
                        </div>
                    </div>
                </div>

                <div class="ui fluid large teal submit button">Login</div>
            </div>
        </form>
        <div class="ui message">
            <p>
                New to us? <a href="#">Sign up</a>
            </p>
        </div>
    </div>
</div>
@endsection`

In my Auth folder, I also have the following code for the LoginController`

public function login(Request $request)
{
    if(Auth::attempt(['email' => $request['email']], ['password' => $request['password']]))
    {
        return redirect()->route('view');
    }

    return redirect()->back();
}

My routes list shows that the routes are of post:

+--------+----------+----------+---------------+----------------------------
---------------------------+--------------+
| Domain | Method   | URI      | Name          | Action                                                
| Middleware   |
+--------+----------+----------+---------------+----------------------------
---------------------------+--------------+
|        | GET|HEAD | /        |               | Closure                                               
| web          |
|        | GET|HEAD | api/user |               | Closure                                               
| api,auth:api |
|        | POST     | login    | auth.login    | 
App\Http\Controllers\Auth\LoginController@login       | web,guest    |
|        | POST     | register | auth.register | 
App\Http\Controllers\Auth\RegisterController@register | web,guest    |
|        | GET|HEAD | view     | view          | 
App\Http\Controllers\ViewController@index             | web          |
+--------+----------+----------+---------------+----------------------------
---------------------------+--------------+

Is there something that isn't typed correctly in the code? Can you use functions in the blade templating engine such as 'action' or 'method'?

  • 写回答

2条回答 默认 最新

  • dsj8000 2017-06-10 22:03
    关注

    Try it like so:

    Route::get('login', ['as' => 'login', 'uses' => 'LoginController@index']);
    Route::post('login', 'LoginController@login');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵