簡體   English   中英

表單提交后500 Internet服務器錯誤

[英]500 Internet Server Error after Form submitting

我從頭開始了laracast教程laravel 5.4。 現在我正處於第12節並且遇到了我的第一個錯誤。 提交空表單后,我獲得500 Internet服務器錯誤。 我嘗試了很多,但我無法解決它。

以下是相關代碼:

web.php

Route::get('/', 'PostsController@index');
Route::get('/posts/create', 'PostsController@create');
Route::post('/posts', 'PostsController@store');

PostController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Post;
class PostsController extends Controller
{
    public function index()      
    {
      return view('posts.index');
    }

     public function show()
    {
        return view('posts.show');
    }
    public function create()
    {
        return view('posts.create');
    }
        public function store()
    {
            $this->validate(request, [
                'title' => 'required',
                'body'=> 'required'
            ]);
            Post::create(request(['title', 'body']));
            return redirect('/');          

    }

}

create.blate.php

@extends('layouts.master')


@section ('content')

<h1>Publish a Post</h1>
<hr>
<form method="POST" action="/posts">
    {{ csrf_field() }}
    <div class="form-group">
    <label for="title">Title</label>
    <input type="text" class="form-control" id="title" name="title">
  </div>
  <div class="form-group">
    <label for="body">Body</label>
    <textarea type="text" class="form-control" id="body" name="body" ></textarea>
  </div>
  <button type="submit" class="btn btn-primary">Publish</button>
</form>

@endsection

post.php中

<?php

namespace App;


class Post extends Model
{

}

Model.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model as Eloquent;

class Model extends Eloquent
{
    protected $guarded = [];
}

希望有人可以幫助我,laravel不要給我一個錯誤。

最好的祝福

如果laravel沒有給你一個錯誤。你可以在你的代碼中設置php內部錯誤提示,看看發生了什么。

error_reporting (E_ALL & ~E_NOTICE);

我找到了錯誤並修復了它...

PostController.php

更換:

$this->validate(request, [ 'title' => 'required', 'body'=> 'required' ]);

有:

$this->validate(request(), [ 'title' => 'required', 'body'=> 'required' ]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM