Download the PHP package abdelrhman-saeed/route without Composer
On this page you can find all versions of the php package abdelrhman-saeed/route. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download abdelrhman-saeed/route
More information about abdelrhman-saeed/route
Files in abdelrhman-saeed/route
Package route
Short Description dynamic routing package
License MIT
Homepage https://github.com/abdelrhman-saeed/route
Informations about the package route
Route
Route
is a dynamic routing package for PHP applications, designed to simplify the creation of RESTful routes.
Installation
Prerequisites
- Entry Point File: Create an entry point file for your application (e.g.,
index.php
). -
Server Configuration: Redirect all requests to this entry point file.
Example using PHP's built-in server:
- Routes File: Create a separate file to define your routes (e.g.,
routes.php
). You can store it anywhere in your project.
Usage Example
index.php:
routes.php:
Route Constraints
You can apply constraints to route segments to validate their format.
Middleware
To add middleware to your routes, extend the AbdelrhmanSaeed\Route\Middleware
class and implement the handle()
method.
Assign middleware to a route:
Resource Routing
The Route::resource()
method automatically generates RESTful routes for a given controller.
This will generate:
GET /users
→UserController::index()
POST /users
→UserController::save()
GET /users/{user}
→UserController::show(mixed $user)
PUT, PATCH /users/{user}
→UserController::update(mixed $user)
DELETE /users/{user}
→UserController::delete(mixed $user)
If you set the api
parameter to false
, two additional routes will be generated:
GET /users/create
→UserController::create()
GET /users/{user}/edit
→UserController::edit(mixed $user)
Nested Resource Routing
You can define nested resource routes using dot notation:
This will generate routes like:
GET /users/{user}/posts
→PostController::index()
POST /users/{user}/posts
→PostController::save()
GET /users/{user}/posts/{post}
→PostController::show(mixed $post)
Apply constraints to nested routes:
Shallow Nesting
Shallow nesting removes the parent ID from child routes when it's unnecessary.
This will generate routes like:
GET /users/posts
→PostController::index()
POST /users/posts
→PostController::save()
GET /users/posts/{post}
→PostController::show(mixed $post)
Middleware Grouping
You can group routes and assign a middleware to all of them:
Controller Grouping
Group routes by a common controller:
You can also combine controller and middleware grouping:
Handling 404 Requests
Define a custom action for 404 responses:
If not defined, a simple 404 HTTP message will be returned.
License
This package is licensed under the MIT License.
All versions of route with dependencies
webonyx/graphql-php Version ^15.19
phpdocumentor/reflection-docblock Version ^5.6