Core concepts

Core concepts you'll use every day

Essentials

Learn the fundamental concepts you'll use in every Glueful application.

Core Topics

HTTP Layer

Data Layer

  • Database - Query builder and connections
  • ORM - Models, relationships and eager loading
  • Migrations - Database schema management

Security

  • Authentication - Login, JWT/refresh tokens, browser sessions, API keys
  • Identity & User Store - The pluggable user store authentication runs on (the skeleton enables glueful/users; core ships none)

Learning Path

New to Glueful? Follow this order:

  1. Routing - Understand how URLs map to code
  2. Controllers - Learn to structure your application logic
  3. Database - Query and store data
  4. Validation - Ensure data integrity
  5. Authentication - Secure your endpoints

Quick Reference

Common Tasks

Create a new endpoint:

// routes/api.php
$router->get('/users', [UserController::class, 'index']);

Query the database:

// Anywhere you hold an ApplicationContext (in a controller: $this->getContext())
$posts = db($context)->table('posts')->where(['status' => 'published'])->get();

Validate input:

use Glueful\Validation\Support\Rules as RuleFactory;
use Glueful\Validation\ValidationException;
use Glueful\Validation\Rules\{Sanitize, Required, Email as EmailRule, Length};
use Glueful\Helpers\RequestHelper;

$input = RequestHelper::getRequestData($request); // decodes JSON or form bodies

$v = RuleFactory::of([
    'email' => [new Sanitize(['trim']), new Required(), new EmailRule()],
    'name'  => [new Sanitize(['trim','strip_tags']), new Required(), new Length(2, 50)],
]);

if ($errors = $v->validate($input)) {
    throw new ValidationException($errors);
}

$data = $v->filtered();

Return JSON:

return Response::success($data);

Next Steps

After mastering the essentials, explore: