使用Laravel7.25版时无法存储在数据库中

问题描述

我试图掌握Laravel框架并在从数据库的页面中检索值时陷入困境。

这些是我的控制器的片段,路线,视图部分,可能有助于了解我在做什么

web.php(用于路由):

<?php

use Illuminate\Support\Facades\Route;

Route::resource('posts','PostController');

Postcontroller.php(只是一个片段)

<?php
public function create()
    {
        //
        return view('posts.create');
    }

       public function store(Request $request)
    {
        //
        $this->validate($request,array(
            'title' => 'required','body' => 'required'
        ));
        $post = new Post;
        $post->title = $request->title;
        $post->body = $request->body;

        $post->save();

        return redirect()->route('posts.show',$post->id);
    }

create.blade.php(用于查看)

<div class="row">
    <div class="col-mid-8 col-md-offset-2" >
        <h1>Create New Post</h1>
        <hr>
        <form route='posts.store' >
            @csrf
            <div class="form-group">
              <label for="exampleInputEmail1">Email address</label>
              <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
              <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
            </div>
            <div class="form-group">
              <label for="exampleInputPassword1">Password</label>
              <input type="password" class="form-control" id="exampleInputPassword1">
            </div>
            <div class="form-group form-check">
              <input type="checkbox" class="form-check-input" id="exampleCheck1">
              <label class="form-check-label" for="exampleCheck1">Check me out</label>
            </div>
            <button type="submit" class="btn btn-primary">Submit</button>
        </form>
    </div>
</div>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)