Sorry most of what you guys have been answering has been returning an empty array, a 404 or an error, really dont know whats going on but i will add how the posts table looks like.. and I will specify each way i tried to apply to the function, since ive tried in several ways. What else could i share so you guys can review? Cheers! @tray2 @marianomoreyra
create_posts_table.php
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->text('title');
$table->string('slug');
$table->text('body');
$table->timestamps();
$table->timestamp('published_at')->nullable();
});
}
This one threw a 404 error. When i added die($post) on this though, the browser rendered the updated post correctly, but once i removed that part it was a 404.
public function update(Post $post, Request $request)
{
$post->title = request('title');
$post->body = request('body');
$post->slug = request('slug');
$post->update();
return redirect('posts/' . $post->slug);
}
This says Method Illuminate\Http\Request::validated does not exist.
public function update(Post $post, Request $request)
{
$post->update($request->validated());
return redirect('posts/' . $post->slug);
}
And since i thought maybe @tray2 wanted to type "validate" instead of "validated" on this method this happened:
Too few arguments to function Illuminate\Http\Request::Illuminate\Foundation\Providers\{closure}(), 0 passed in /Users/eduardocoello/Projects/newport/vendor/laravel/framework/src/Illuminate/Macroable/Traits/Macroable.php on line 114 and exactly 1 expected
This way it returned an empty array when the die method was applied, which meant that the post didnt update:
public function update(Post $post, Request $request)
{
$post->update(['post' => $request->post]);
return redirect('posts/' . $post->slug);
}
Also an empty array:
public function update(Post $post, Request $request)
{
$post->update([
'title' => $request->title,
'body' => $request->body,
'slug' => $request->slug
]);
return redirect('posts/' . $post->slug);
}
Empty array:
public function update(Post $post, Request $request)
{
$validatedData = $request->validate([
'title' => 'required|unique:posts|max:255',
'body' => 'required',
'slug' => 'required',
]);
$post->update($validatedData);
return redirect('posts/' . $post->slug);
}