When I went to create the edit functionality with (Laravel 8) I faced the the above said error for the first time. It seems from googling that I am not the only one to have been facing this error, and it was not a straight forward problem to solve. Each case has it is own individual case and so it required its own relevant solution. I would extremely thankful for assistances from more experienced users and I would appreciate it so much.
show.blade.php
@extends('layouts.app')
@section('content')
<a href="/posts" class="btn btn-danger">Go Back</a>
<h3>{{$post->title}}</h3>
<div>
{!! $post->content !!}
</div>
<hr>
<small>written on {{$post->created_at}}</small>
<hr>
<a href="/posts/{{$post->id}}/edit" class="btn btn-primary">Edit</a>
@endsection
Edit.blade.php
@extends('layouts.app')
@section('content')
{!! Form::open(['action' => ['PostsController@update', $post->id], 'method'=>'POST']) !!}
<div class="form-group">
{{Form::label('title', 'Title')}}
{{Form::text('title', $post->title, ['class'=>'form-control', 'placeholder'=>'title'])}}
</div>
{!! '<br>' !!}
<div class="form-group">
{{Form::label('body', 'Body')}}
{{Form::textarea('body', $post->content, ['class'=>'form-control ckeditor', 'placeholder'=>'content'])}}
</div>
{{Form::hidden('_method', 'PUT')}}
{!! Form::submit('Submit', ['class'=>'btn btn-primary']) !!}
{!! Form::close() !!}
@endsection
PostsController.php
public function show($id)
{
$post = Post::find($id);
return view('posts.show')->with('post', $post);
}
public function edit($id)
{
$post = Post::find($id);
return view('posts.edit')->with('post', '$post');
}
public function update(Request $request, $id)
{
Return "Update";
}
Post.php Model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
//
}