Editing a post/task/anything is just like creating a new one but with a patch request and a update method instead of post and create.
Edit.blade.php:
<form action="/editpost/{{$post->id}}" method="post">
{{ csrf_field() }}
//method field is used to tell the browser that this "post" is actually a patch request
{{ method_field('PATCH') }}
// Here goes the edit form that can be exactly like your create post but with the values of the post you are editing
</form>
web.php:
Route::patch('/editpost/{id}', 'PostController@update');
PostController:
public function update($id){
//validate as usual
request()->validate([
'title' => 'required',
'description' => 'required'
]);
//Now instead of just creating a new one we are going to update the one we want
Post::find($id)->update([
'title' => request('title'),
'channel_id' => 2,
'description' => request('description')
]);
//some fancy feedback message
return back()
}
And yep, that's all you need. If you are able to create post you shouldn't have more problem editing them. Just remember that you need to find the post you want to update using the id, that you need to submit a patch request (or make it with a post if you want but using get+post+patch+delete let's you make everything with one single route.
The Trying to get property of non-object means that you are passing a null value either through a relationship or to a value you are using in some logic (for example a null date that you are formatting).