1. Go to this page and download the library: Download vireo/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/ */
vireo / framework example snippets
// Using helper functions
route('users.show', ['id' => 123]); // Generate URL
redirect('dashboard'); // Redirect to named route
namespace App\Features\Users;
use Vireo\Framework\Http\Controller;
class ShowUser extends Controller
{
public function __invoke(int $id)
{
$user = table('users')->where('id', $id)->first();
// Return JSON for API requests
if ($this->isApi()) {
return $this->json(['user' => $user]);
}
// Return Inertia response for web
return $this->inertia('Users/Show', ['user' => $user]);
}
}
// Check permissions
if (can('users.edit')) {
// User can edit users
}
// Check with attribute
if (can('projects.edit', null, 'department', 'engineering')) {
// User can edit projects in engineering department
}
// Multiple permission check
if (can_any(['users.view', 'users.edit'])) {
// User has at least one permission
}
use Vireo\Framework\Database\Migrations\Migration;
return new class extends Migration
{
public function up(): void
{
$this->create('users', function ($table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->timestamps();
});
}
public function down(): void
{
$this->drop('users');
}
};
// Get config value
$appName = config('app.name');
$dbHost = config('database.connections.mysql.host');
// Get with default
$debug = config('app.debug', false);
// Get environment variable
$apiKey = env('API_KEY');
// With default value
$debug = env('APP_DEBUG', false);
// Set session value
session_set('user_id', 123);
// Get session value
$userId = session_get('user_id');
// Check if exists
if (session_has('user_id')) {
// ...
}
// Remove session value
session_forget('user_id');
// Log messages at different levels
log_debug('Debug information', ['context' => $data]);
log_info('User logged in', ['user_id' => $userId]);
log_warning('Deprecated feature used');
log_error('Something went wrong', ['exception' => $e->getMessage()]);
// Store a file
storage()->put('uploads/avatar.jpg', $fileContents);
// Get file contents
$contents = storage()->get('uploads/avatar.jpg');
// Check if file exists
if (storage()->exists('uploads/avatar.jpg')) {
// ...
}
// Delete a file
storage()->delete('uploads/avatar.jpg');