1. Go to this page and download the library: Download lugege/laravel-aspect 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/ */
lugege / laravel-aspect example snippets
use Lugege\LaravelAspect\EasyRouter;
EasyRouter::register();
use Lugege\LaravelAspect\Attributes\Routes\GetMapping;
use Lugege\LaravelAspect\Attributes\Routes\Prefix;
#[Prefix(path: '/user')]
class UserController
{
#[GetMapping(path: '/login')]
public function login() {}
}
use Lugege\LaravelPlus\Attributes\Service;
#[Service]
class UserService
{
public function register() {}
}
use Lugege\LaravelPlus\Traits\Injectable;
class UserController
{
use Injectable;
#[Autowired]
private UserService $userService;
public function register()
{
$this->userService->register();
}
}
use Lugege\LaravelPlus\Traits\Injectable;
use Lugege\LaravelPlus\Attributes\Value;
class DatabaseService
{
use Injectable;
#[Value('database.connections.mysql.host', 'localhost')]
private string $dbHost;
#[Value('database.connections.mysql.port', 3306)]
private int $dbPort;
#[Value('app.timezone', 'UTC')]
private string $timezone;
public function connect()
{
// 使用注入的配置值
dump("Connecting to {$this->dbHost}:{$this->dbPort}");
}
}