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 爬取豆瓣电影相关处理
  • ¥15 手机淘宝抓清除消息接口
  • ¥15 C#无selenium
  • ¥15 LD衰减计算的结果过大
  • ¥15 用机器学习方法帮助保险公司预测哪些是欺诈行为
  • ¥15 计算300m以内的LD衰减
  • ¥15 数据爬取,python
  • ¥15 怎么看 cst中一个面的功率分布图,请说明详细步骤。类似下图
  • ¥15 为什么我的pycharm无法用pyqt6的QtWebEngine
  • ¥15 FOR循环语句显示查询超过300S错误怎么办