Комментарии:
Can someone tell me how the auth()->id()
Works?,
Hey it's me again I still get the "SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value" Error but I set in the "Idea.php" Model I set it to fillable.
My Code for a reverence:
Idea.php:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Idea extends Model
{
use HasFactory;
protected $fillable = [
'user_id',
'content',
'like',
];
public function comments()
{
return $this->hasMany(Comment::class);
}
}
IdeasController store method:
public function store()
{
$validated = request()->validate([
'content' => 'required|min:5|max:240'
]);
$validated['auth_id'] = auth()->id();
Idea::create($validated);
return redirect()->route('ideas.dashboard')->with('success', 'Idea created successfully');
}
And THANKS A LOT for the help and this good cours
Any suggestions on why when I click on post comment, it doesn't show the success message?
ОтветитьWhat about comment section?
how to keep track about comments added by different users on a idea?
what theme are you using?
Ответитьwhy am i getting this error "Attempt to read property "name" on null" when echoring the user name on {{$idea->user->name}} in the blade file.
ОтветитьIs it possible that when I write the same code as you, I get an error but you not. After being frustrated, I tried to write the same code, and it's worked :)
Ответитьexercise done hehe @if(auth()->id() == $idea->user_id) put to the buttons hehe
ОтветитьLaravel is simple because of YOU! Thanks a lot.
Ответитьthanks for your cours man , your a big help , don't stop sooner or later you will have more subs ,
Ответить