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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀