PHP code example of smhdhsn / zed
1. Go to this page and download the library: Download smhdhsn/zed 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/ */
smhdhsn / zed example snippets
$router->get('/projects', function () {
return 'Hello, World !';
});
$router->get('/projects', 'ProjectController@index');
use App\Controllers\ProjectController;
$router->get('/projects', [ProjectController::class, 'index']);
$router->get('/project/:projectId', 'ProjectController@show', [
'checkAvailability'
]);
$router->get('/project/:projectId', 'ProjectController@show', [
'auth'
]);
$router->get('/projects/:projectId/logs/:logId', 'ProjectController@index');
namespace App\Controllers;
use Zed\Framework\{Controller, Request};
class ProjectController extends Controller
{
/**
* Showing project's index page.
*
* @param Request $request
* @param int $projectId
* @param int $logId
*
* @return string
*/
public function index(Request $request, int $projectId, int $logId): string
{
//
}
}
$request->projectName;
$request->validate([
'name' => 'ue:users,email',
'password' => '
$request->validate([
'name' => '
$request->validate([
'surname' => 'string',
]);
$request->validate([
'age' => 'numeric',
]);
$request->validate([
'email' => 'email',
]);
$request->validate([
'password' => 'max:64',
]);
$request->validate([
'name' => 'min:5',
]);
$request->validate([
'email' => 'unique:users,email',
]);
namespace App\Controllers;
use Zed\Framework\{Controller, Request, Response};
class ProjectController extends Controller
{
/**
* Showing project's index page.
*
* @param Request $request
* @param int $projectId
* @param int $logId
*
* @return string
*/
public function index(Request $request, int $projectId, int $logId): string
{
$data = "{$projectId} - {$logId}";
return $this->response(
Response::SUCCESS,
$data,
Response::HTTP_OK
);
}
}
namespace App\Controllers;
use Zed\Framework\{Controller, Request, Response};
use Exception;
class ProjectController extends Controller
{
/**
* Showing project's index page.
*
* @param Request $request
* @param int $projectId
* @param int $logId
*
* @return string
*/
public function index(Request $request, int $projectId, int $logId): string
{
$data = "{$projectId} - {$logId}";
try {
return $this->response(
Response::SUCCESS,
$data,
Response::HTTP_OK
);
} catch (Exception $exception) {
return $this->error(
Response::ERROR,
$exception->getMessage(),
Response::HTTP_INTERNAL_SERVER_ERROR
);
}
}
}
Project::create([
'author' => $request->author,
'name' => $request->name,
'type' => $request->type
]);
Project::where('name', $request->name)->get();
Project::find($id);
$project = Project::find($id);
$project->update([
'name' => $request->name,
'type' => $request->type
]);
$project = Project::find($id);
$project->delete();
$command->define('command-name', \App\Command\YourCommand::class);
$command->modify('command-name', function () {
//
});
use Zed\Framework\CommandLineInterface as CLI;
$command->modify('say', function (string $message = 'Hello') {
return CLI::out($message);
});
shell
php command serve
shell
php command serve --port=8080
shell
php command say 'Hello World !'
shell
php command migrate
shell
php command migrate:rollback
shell
php command migrate:reset
shell
php command migrate:fresh
shell
php command make:controller UserController
shell
php command make:model User
shell
php command make:repository UserRepository
shell
php command make:service UserCreatingService