Blog is not displayed or stored correctly in the database
<p>Once I delete a blog, it is completely deleted. I can create a new blog but it won't show up on the website or database. This is my BlogController: </p>
<pre class="brush:php;toolbar:false;"><?php
namespace App\Http\Controllers;
use App\Models\Blog;
use Illuminate\Http\Request;
class BlogController extends Controller
{
/*** Display resource list.
*
* @return \Illuminate\Http\Response*/
public function index()
{
$blog = Blog::paginate(5);
return view('blogs.index', compact('blog'))
->with('i',(request()->input('page',1)-1)*5);
}
/*** Display the form for creating new resources.
*
* @return \Illuminate\Http\Response*/
public function create()
{
return view('blogs.create');
Blog::create($request->all());
return redirect()->route('blogs.index')
->with('success','The blog was created successfully.');
}
/*** Store newly created resources in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response*/
public function store(Request $request)
{
$request->validate([
'title' => 'required',
'description' => 'required',
]);
$blog = new Blog;
$blog->title = $request->title;
$blog->description = $request->description;
$blog->save();
return redirect()->route('blogs.index');
}
/*** Display the specified resource.
*
* @param \App\Blog $blog
* @return \Illuminate\Http\Response*/
public function show(Blog $blog)
{
return view('blogs.show', compact('blog'));
}
/*** Display the form for editing the specified resource.
*
* @param \App\Blog $blog
* @return \Illuminate\Http\Response*/
public function edit(Blog $blog)
{
return view('blogs.edit', compact('blog'));
}
/*** Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Blog $blog
* @return \Illuminate\Http\Response*/
public function update(Request $request, Blog $blog)
{
$request->validate([
'title' => 'required',
'description' => 'required',
]);
// $blog->title = $request->title;
// $blog->description = $request->description;
$blog->fill($request);
//dd($blog);
return redirect()->route('blogs.index')
->with('success','Blog updated successfully');
}
/**
* Remove the specified resource from storage.*
* @param \App\Blog $blog
* @return \Illuminate\Http\Response
*/
public function destroy(Blog $blog)
{
$blog->delete();
return redirect()->route('blogs.index')
->with('success','Blog deleted successfully');
}
}</pre>
<p>The problem apparently occurs at line 103, public function update: <code> $blog->fill($request);</code> It is neither stored in the database nor in the web page/blog visible. I tried removing that line but got the same result. Nothing changes. I don't understand what the problem could be. Can anyone help? </p>