Mardira Framework is a PHP framework Model Controller Based for building web applications and APIs. It is designed to be simple, and fast.
mardira-framework
├── App
│ ├── Controllers
│ │ ├── AuthController.php
│ ├── Core
│ │ ├── Commands
│ ├── Database
│ │ ├── Migrations
│ │ │ ├── 2023_01_31_xxxxxx_create_table_users.php
│ │ │ ├── 2023_01_31_xxxxxx_create_table_roles.php
│ │ ├── Seeders
│ │ │ ├── GlobalSeeder.php
│ ├── Helpers
│ ├── Middleware
│ ├── Models
│ ├── Packages
│ ├── Routes
│ │ ├── Api.phpYou can create a new project using composer
composer create-project mardira/mardira-framework <your_project_name>or you can clone this project
git clone https://github.com/Bootcamp-STMIK-Mardira-Indonesia/mardira-framework.gitThen, install the dependencies using composer
composer installor
composer updatephp mardira serveor
php mardira serve --port=<your_port>You can create .env file using command
php mardira make:envphp mardira make:controller ControllerNamephp mardira make:model ModelNamephp mardira make:route route_name --controller=ControllerNamephp mardira make:migration create_table_table_nameIf database not exist, will automatically create database from .env
php mardira migratephp mardira migrate:refreshphp mardira migrate:refresh --seedphp mardira make:seeder SeederNamephp mardira db:seedphp mardira db:seed --class=SeederNamephp mardira make:authphp mardira make:auth --refreshphp mardira updateCreate controller use
php mardira make:controller ControllerName, here is example controller
<?php
namespace AppControllers;
use AppCoreController;
class HomeController extends Controller
{
public function index()
{
$this->response(200,[
'message' => 'Hello World'
]);
}
}to use controller, you can add route in
App/Routes/Api.php
<?php
use AppCoreRoute;
use AppControllersHomeController;
Route::get('/home', [HomeController::class, 'index']);You can use response in controller
$this->response(200,[
'message' => 'Hello World'
]);return json expected
{
"message": "Hello World"
}another response example 409
$this->response->json(409,[
'message' => 'Conflict'
]);Create model use
php mardira make:model ModelName, here is example model
<?php
namespace AppModels;
use AppCoreModel;
class User extends Model
{
protected $table = 'users';
protected $primaryKey = 'id';
}to use model, you can add model in
App/Controllers/ControllerName.php
<?php
namespace AppControllers;
use AppCoreController;
use AppModelsUser;
class HomeController extends Controller
{
public function index()
{
$user = User::all();
$this->response(200,[
'message' => 'Hello World',
'data' => $user
]);
}
}Create migration use
php mardira make:migration create_table_table_name, here is example migration
<?php
namespace AppDatabaseMigrations;
use AppCoreMigration;
return new class extends Migration
{
public function up()
{
$this->schema->create('users', function ($table) {
$table->increment('id');
$table->string('name', 50);
$table->string('email',50)->unique();
$table->string('password', 64);
$table->timestamps();
});
}
public function down()
{
$this->schema->dropIfExists('users');
}
}Create seeder use
php mardira make:seeder SeederName, here is example seeder
<?php
namespace AppDatabaseSeeders;
use AppCoreSeeder;
use AppCoreQueryBuilder as DB;
class UserSeeder extends Seeder
{
public function run()
{
$data = [
[
'name' => 'Administrator',
'username' => 'admin',
'email' => '[email protected]',
'password' => password_hash('password', PASSWORD_DEFAULT),
'role_id' => 1,
],
[
'name' => 'User',
'username' => 'user',
'email' => '[email protected]',
'password' => password_hash('password', PASSWORD_DEFAULT),
'role_id' => 2,
]
];
DB::table('users')->insert($data);
}
}Create middleware use
php mardira make:middleware MiddlewareName, here is example middleware
<?php
namespace AppMiddleware;
use AppCoreMiddleware;
use AppCoreAuth;
class AuthMiddleware extends Middleware
{
public function handle()
{
if (Auth::check()) {
return $next();
}
return $this->response(401, ['message' => 'Unauthorized']);
}
}to use middleware, you can add middleware in route
Router::get('/schedules', [ScheduleController::class, 'index'], [AuthMiddleware::class]);You can add route in
App/Routes/Api.php
<?php
use AppCoreRoute;
Router::get('/home', [HomeController::class, 'index']);You can add route group in
App/Routes/Api.php
<?php
use AppCoreRoute;
Router::controller(ProductController::class)->group(function () {
Router::post('/products/store', 'store');
});use AppCoreQueryBuilder as DB;DB::table('users')->select('name', 'email')->get();// equal
DB::table('users')->where('id', 1)->get();
DB::table('users')->where('id', 1, '>')->get();
DB::table('users')->where('id', 1, '<')->get();
DB::table('users')->where('id', 1, '>=')->get();
DB::table('users')->where('id', 1, '<=')->get();
DB::table('users')->where('id', 1, '!=')->get();
DB::table('users')->where('id', 1, '<>')->get();
// like
DB::table('users')->where('name', 'admin', 'like')->get();
DB::table('users')->where('name', 'admin', 'not like')->get();DB::table('users')->orWhere('id', 1)->get();
DB::table('users')->orWhere('id', 1, '>')->get();
DB::table('users')->orWhere('id', 1, '<')->get();
DB::table('users')->orWhere('id', 1, '>=')->get();
DB::table('users')->orWhere('id', 1, '<=')->get();
DB::table('users')->orWhere('id', 1, '!=')->get();
DB::table('users')->orWhere('id', 1, '<>')->get();DB::table('users')->whereIn('id', [1,2,3])->get();
DB::table('users')->whereNotIn('id', [1,2,3])->get();DB::table('users')->whereNotIn('id', [1,2,3])->get();DB::table('users')->whereNull('id')->get();DB::table('users')->whereNotNull('id')->get();DB::table('users')->orderBy('id', 'desc')->get();
DB::table('users')->orderBy('id', 'asc')->get();DB::table('users')
->join('roles', 'users.role_id', '=', 'roles.id')
->select('users.*', 'roles.name as role_name')
->get();DB::table('users')
->groupBy('role_id')
->get();DB::table('users')->insert([
'name' => 'user',
'email' => '[email protected]',
'password' => password_hash('password', PASSWORD_DEFAULT),
]);DB::table('users')->where('id', 1)->update([
'name' => 'user',
'email' => '[email protected]',
]);DB::table('users')->where('id', 1)->delete();DB::table('users')->count();Reach out to me at one of the following places!
demostmikmi.com