1. Go to this page and download the library: Download roy404/framework 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/ */
roy404 / framework example snippets
use App\Routes\Route;
use Handler\Controller\UserController;
Route::get('/', function () {
return view('welcome');
});
Route::get('/users/{id}', [UserController::class, 'show']);
use App\Console\Schedule;
Schedule::command('clear:logs')->daily();
Schedule::command('emails:send')->everyFiveMinutes();
Schedule::command('report:generate')->at('14:30');
namespace Handler\Middleware;
use App\Utilities\Request;
class Account
{
/**
* Handle an incoming request.
*
* This method is automatically invoked before a route or controller is executed.
* You can perform validation, authentication, or any pre/post request logic here.
*
* @param Request $request
* @return mixed
*/
public function handle(Request $request)
{
// Example pre-processing: authentication/validation
if (!$this->authorize($request)) {
return redirect('/unauthorized', 403);
}
$response = 'ok!';
// Example post-processing: logging, response modification
$this->log($request, $response);
// Return true to continue request processing
return true;
}
/**
* Perform authorization/validation logic.
*/
protected function authorize(Request $request): bool
{
// Default: allow all requests
return true;
}
/**
* Example logging or post-processing.
*/
protected function log(Request $request, mixed $response): void
{
// You could log request details here
}
}
namespace Handler\Controller;
use App\Http\Controller;
use App\Utilities\Request;
class UserController extends Controller
{
public function show(Request $request, int $id)
{
return view('users.show', ['user' => User::find($id)]);
}
}
namespace Handler\Model;
use App\Databases\Facade\Model;
class User extends Model
{
public string $primary_key = 'id';
public string $table = 'users';
public array $fillable = ['id', 'name', 'email'];
}
$users = App\Databases\Database::server('master')
->query("SELECT * FROM users")
->fetch();
use App\Databases\Schema;
use App\Databases\Handler\Blueprints\Table;
Schema::create('users', function (Table $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamps();
});
use App\Databases\Schema;
use App\Databases\Handler\Blueprints\Table;
Schema::table('users', function (Table $table) {
$table->string('phone')->nullable();
});
use App\Databases\Schema;
// Rename table
Schema::renameTable('users', 'members');
// Drop table if it exists
Schema::dropIfExists('sessions');
// Drop table permanently
Schema::drop('logs');
use App\Databases\Schema;
// Check if table exists
Schema::hasTable('users');
// Get column info
Schema::column('users', 'email');
// Fetch all columns
Schema::fetchColumns('users');
// Drop a column
Schema::dropColumn('users', 'phone');
// Rename a column
Schema::renameColumn('users', 'fullname', 'name', 'VARCHAR(255)');
use App\Databases\Schema;
// Add index
Schema::addIndex('users', 'email');
// Drop index
Schema::dropIndex('users', 'email_index');
// Fetch index details
Schema::index('users', 'email_index');
use App\Databases\Schema;
// Change storage engine
Schema::setEngine('users', 'InnoDB');
// Change character set and collation
Schema::setCharset('users', 'utf8mb4', 'utf8mb4_unicode_ci');
// Truncate a table
Schema::truncate('users');
// Get CREATE TABLE statement for export/backup
$definition = App\Databases\Schema::exportTable('users');
namespace Components;
use App\Utilities\Handler\Component;
class Counter extends Component
{
public $count = 0;
public function increment()
{
$this->count++;
}
/**
* @see ./views/components/counter.blade.php
*/
public function render()
{
return $this->compile([
'count' => $this->count
]);
}
}
blade
{{-- Escaped output (HTML is escaped) --}}
<p>{{ '<strong>This will not render as bold</strong>' }}</p>
{{-- Unescaped output (HTML will render) --}}
<p>{!! '<strong>This will render as bold text</strong>' !!}</p>
{{-- Conditional statements --}}
@if($isAdmin)
<p>You have admin access.</p>
@elseif($isUser)
<p>You are logged in as a regular user.</p>
@else
<p>Please log in to continue.</p>
@endif
{{-- Loops --}}
<ul>
@foreach($tasks as $task)
<li>{{ $loop->iteration }}. {{ $task }}</li>
@endforeach
</ul>
{{-- Including other templates --}}
@
bash
php artisan [command]
bash
# Start the local development server
php artisan serve