1. Go to this page and download the library: Download omega-mvc/omega library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
omega-mvc / omega example snippets
// database/migrations/<timestamp>_profiles.php
use Omega\Database\Facades\Schema;
use Omega\Database\Schema\Table\Create;
return [
'up' => [
Schema::table('profiles', function (Create $column) {
$column('user')->varChar(32);
$column('real_name')->varChar(100);
$column->primaryKey('user');
}),
],
'down' => [
Schema::drop()->table('profiles'),
],
];
// app/Http/Controllers/ProfileController.php
namespace App\Http\Controllers;
use App\Models\Profile;
use Omega\Database\ConnectionInterface;
use Omega\Http\Response;
use function Omega\View\view;
class ProfileController extends AbstractController
{
public function handle(ConnectionInterface $pdo): Response
{
return view('profile', [
'name' => Profile::find('omega-mvc', $pdo)->real_name
]);
}
}
// app/Services/ProfileServices.php
use App\Models\Profile;
use Omega\Cache\Facade\Cache;
use Omega\Database\ConnectionInterface;
use Omega\Http\JsonResponse;
use Omega\Router\Attribute\Middleware;
use Omega\Router\Attribute\Name;
use Omega\Router\Attribute\Route\Get;
class ProfileServices
{
#[Get('/api/v1/profile')]
#[Name('api.v1.profile')]
#[Middleware([AuthMiddleware::class])]
public function index(ConnectionInterface $pdo): JsonResponse
{
$data = Cache::remember('profile', fn () => [
'name' => Profile::find('omega-mvc', $pdo)->real_name,
'status' => 200,
], 3600);
return new JsonResponse($data);
}
}
Router::register([
ProfileServices::class,
// add more class
]);