Eloquent для чайников

use Illuminate\Database\Eloquent\Model;
 
class Post extends Model
{
      /**
      * Get the publisher for this model.
      */
      public function publisher()
      {
          # ( $modelClass , $foreign_key , $object_id )
          return $this->belongsTo(User::class, 'user_id', 'id');
      }
}

Расширяем возможности builder'ов

namespace App\QueryBuilders;
 
use App\Models\User;
use Carbon\CarbonImmutable;
use Illuminate\Database\Eloquent\Builder;
 
/**
 * @template TModelClass
 * @extends Builder<TModelClass>
 */
class ChatLineQueryBuilder extends Builder
{
    public function forToday(): self
    {
        return $this->whereDay('day', CarbonImmutable::now());
    }
 
    public function forUser(User $user): self
    {
        return $this->where('user_id', $user->id);
    }
}