我写了一些有关laravel的帖子,但这绝对是我经历过的最难熬的时候。我正在为自己编写一个博客应用程序以学习Laravel,直到我从以下位置更改文件结构之前,它的运行都非常流畅:
-[views] --[blogs] ---index.blade.php ---create.blade.php ---show.blade.php
收件人:
-[views] --index.blade.php --create.blade.php --[admin] ---show.blade.php
这是我的路线文件:
Route::get('/', 'Blogs@index')->name('blogs_path'); Route::get('/admin/create', 'Blogs@create')->name('create_blogs_path'); Route::get('/', 'Blogs@store')->name('store_blogs_path'); Route::get('/{id}', 'Blogs@show')->name('blog_path');
这是我的博客控制器文件:
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Blog; class Blogs extends Controller { // public function index(){ $blogs = Blog::all(); return view('index', ['blogs' => $blogs]); } public function show($id){ $blog = Blog::find($id); return view('show', ['blog' => $blog]); } public function create(){ return view('admin.create'); } public function store(Request $request){ $blog = new Blog; $blog->title = $request->title; $blog->content = $request->content; $blog->created_at = $request->created_at; $blog->save(); return redirect()->route('blogs_path'); } }
在旧的文件结构中,它工作得很好,但是当我将其恢复一级时,一切都崩溃了。这是我得到的错误:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be null (SQL: insert into 'blogs' ('title', 'content', 'created_at', 'updated_at') values (?, ?, ?, 2020-04-23 20:10:20))
但是我在表中有数据,之前它工作得很好。
谢谢。
我写了一些有关laravel的帖子,但这绝对是我经历过的最难熬的时候。我正在为自己制作一个博客应用程序以学习Laravel,直到我更改文件之前,它的运行都非常流畅...
/
路径重复两次: