In this lesson, let's show a column from the relationship in the posts table. We will add a category for every post.

First, we need to create a Category model and migration.
php artisan make:model Category -m
database/migrations/xxxx_create_categories_table.php:
public function up(): void{ Schema::create('categories', function (Blueprint $table) { $table->id(); $table->string('name'); $table->timestamps(); });}
app/Models/Category.php:
class Category extends Model{ protected $fillable = [ 'name', ];}
Next, we need to create a migration...
while i use public function category(): BelongsTo in app/Models/Post.php i get this error App\Models\Post::category(): Return value must be of type App\Models\BelongsTo, Illuminate\Database\Eloquent\Relations\BelongsTo returned i removed : BelongsTo from function category and now work.
It also needs to have BelongsTo in the
usesection on top.