1. Go to this page and download the library: Download mawsis/nebula-php 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/ */
mawsis / nebula-php example snippets
// public/index.php
ateImmutable(dirname(__DIR__))->safeLoad();
Nebula\Core\Config::load(dirname(__DIR__) . '/config');
$app = new Nebula\Core\Application(dirname(__DIR__));
use Nebula\Core\Facades\Route;
use App\Controllers\AuthController;
use App\Controllers\UserController;
Route::get('/users', [UserController::class, 'listUsers'], ['auth']);
Route::get('/users/{id}', [UserController::class, 'showUser'], ['auth']);
Route::post('/login', [AuthController::class, 'loginStore']);
public function listUsers(Request $request, Response $response)
{
$users = Paginator::paginate(User::query()->orderBy('id', 'ASC'), $response);
return $response->json(['users' => $users]);
}
namespace App\Models;
use Nebula\Core\DbModel;
class Post extends DbModel
{
public static function tableName(): string { return 'posts'; }
public static function primaryKey(): string { return 'id'; }
public static function attributes(): array { return ['title', 'body', 'user_id']; }
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
}
use Nebula\Core\Facades\Auth;
use Nebula\Core\Middlewares\BaseMiddleware;
use Nebula\Core\Exceptions\ForbiddenException;
class AdminMiddleware extends BaseMiddleware
{
public function execute()
{
if (Auth::isGuest() || !Auth::user()->is_admin) {
throw new ForbiddenException();
}
}
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.