【问题标题】:Laravel - Access forbidden! You don't have permission to access the requested object. It is either read-protected or not readable by the serverLaravel - 禁止访问!您无权访问请求的对象。它要么是读保护的,要么是服务器不可读的
【发布时间】:2016-02-03 23:13:00
【问题描述】:

php

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Laravel PHP Framework</title>

</head>
<body>
  <div class="welcome">
      <h1>test page</h1>

      <form action="{{ URL::route('dis') }}" method="post">
        First name:<br>
        <input type="text" name="firstname"><br>
        Last name:<br>
        <input type="text" name="lastname">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">

        <input type="submit">   
      </form>

  </div>
</body>
</html> 

display.blade.php

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>display page</title>

</head>
<body>
    <div class="welcome">
        <h1>test page for display</h1>

    </div>
</body>
</html>

Routes.php

<?php
 Route::get('/', array('uses'=>'HomeController@showWelcome', 'as' => 'home'));

 Route::group(array('before'=>'csrf'),function()
 {
     Route::post('/dis', array('uses'=>'HomeController@display', 'as' => 'dis'));
 });

HomeController.php

<?php

class HomeController extends BaseController {


    public function showWelcome()
    {
        return View::make('hello');
    }

    public function display()
    {
        return View::make('display');
    }

 }

laravel 5 有错误, 当我尝试提交表单 hello.html 时出现以下错误。

禁止访问! 您无权访问请求的对象。服务器要么读保护要么不可读。

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    我看到的一件事是您需要表单中的 CSRF 令牌。如果你还安装了illuminate\html(现在 Laravel 5 中不包含它),你可以使用 Form::open 来获取它,而不是像你一样在 HTML 中创建 &lt;form&gt; 标签。

    或者,您可以通过调用csrf_field 函数将令牌添加到表单:

    {!! csrf_field() !!}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-19
      • 2018-08-14
      • 2021-06-20
      • 2020-06-27
      • 1970-01-01
      • 2019-09-11
      • 2014-06-07
      • 2018-08-06
      相关资源
      最近更新 更多