Skip to content

Commit 5a565cf

Browse files
committed
first init
0 parents  commit 5a565cf

11 files changed

+721
-0
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Changelog
2+
3+
All notable changes to `laravel-api-helpers` will be documented in this file
4+
5+
## 1.0.0 - 201X-XX-XX
6+
7+
- initial release

CONTRIBUTING.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Contributing
2+
3+
Contributions are **welcome** and will be fully **credited**.
4+
5+
Please read and understand the contribution guide before creating an issue or pull request.
6+
7+
## Etiquette
8+
9+
This project is open source, and as such, the maintainers give their free time to build and maintain the source code
10+
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
11+
extremely unfair for them to suffer abuse or anger for their hard work.
12+
13+
Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
14+
world that developers are civilized and selfless people.
15+
16+
It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
17+
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
18+
19+
## Viability
20+
21+
When requesting or submitting new features, first consider whether it might be useful to others. Open
22+
source projects are used by many developers, who may have entirely different needs to your own. Think about
23+
whether or not your feature is likely to be used by other users of the project.
24+
25+
## Procedure
26+
27+
Before filing an issue:
28+
29+
- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
30+
- Check to make sure your feature suggestion isn't already present within the project.
31+
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
32+
- Check the pull requests tab to ensure that the feature isn't already in progress.
33+
34+
Before submitting a pull request:
35+
36+
- Check the codebase to ensure that your feature doesn't already exist.
37+
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
38+
39+
## Requirements
40+
41+
If the project maintainer has any additional requirements, you will find them listed here.
42+
43+
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).
44+
45+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
46+
47+
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
48+
49+
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
50+
51+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
52+
53+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
54+
55+
**Happy coding**!

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) omar alalwi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
<p align="center">
2+
<h1 align="center">Laravel API Helpers 🚀</h1>
3+
<p align="center">**Laravel API Helpers** is a collection of helper functions designed to streamline API development with Laravel. It enables you to easily detect API versions, validate requests, and access useful request details—all while keeping your code clean and maintainable. ✨</p>
4+
5+
<p align="center">
6+
<a href="https://packagist.org/packages/omaralalwi/laravel-api-helpers">
7+
<img src="https://img.shields.io/packagist/v/omaralalwi/laravel-api-helpers" alt="Latest Version">
8+
</a>
9+
<a href="https://php.net">
10+
<img src="https://img.shields.io/badge/PHP-7.4%2B-blue" alt="PHP Version">
11+
</a>
12+
<a href="LICENSE.md">
13+
<img src="https://img.shields.io/badge/license-MIT-brightgreen" alt="License">
14+
</a>
15+
<a href="https://github.com/omaralalwi/laravel-api-helpers/actions">
16+
<img src="https://img.shields.io/github/actions/workflow/status/omaralalwi/laravel-api-helpers/tests.yml" alt="Tests Status">
17+
</a>
18+
</p>
19+
20+
## 🌟 Features
21+
22+
- **API Version Detection:** Determine the API version from the request URL or headers.
23+
- **API Version Validation:** Check if the current request matches or exceeds a specified API version.
24+
- **API Request Identification:** Identify if a request is targeting the API.
25+
- **Request Helpers:** Retrieve client IP, locale, token, content type, headers, and check for secure requests.
26+
- **Authentication Helpers:** Determine API authentication status and retrieve the authenticated user.
27+
28+
## 📋 Requirements
29+
30+
- PHP 7.4 or higher
31+
- Laravel 7.x or higher
32+
33+
## 🛠️ Installation
34+
35+
Install the package via Composer:
36+
37+
```bash
38+
composer require omaralalwi/laravel-api-helpers
39+
```
40+
41+
## 📦 Usage
42+
43+
The helper functions are globally available throughout your Laravel application. You can call them anywhere—controllers, middleware, or routes or blade files.
44+
45+
---
46+
47+
## 📚 API Helper Functions Guide
48+
49+
### 🔍 . `get_api_v()`
50+
51+
Extracts the API version from the current request by inspecting the URL (e.g., `api/v4`) or the `Accept-Version` header.
52+
53+
```php
54+
$apiVersion = get_api_v();
55+
```
56+
57+
---
58+
59+
### ✅ . `is_api_v($version)`
60+
61+
Determines if the current request is for a specific API version by comparing the detected version with the provided one.
62+
63+
```php
64+
// Check if the current API version is 3
65+
if (is_api_v(3)) {
66+
echo "This is API version 3. ✅";
67+
} else {
68+
echo "This is not API version 3. ❌";
69+
}
70+
```
71+
72+
---
73+
74+
### ⏫ . `api_v_at_least($version)`
75+
76+
Checks whether the current API version is at least a specified minimum version.
77+
78+
```php
79+
// Verify that the API version is at least version 4
80+
if (api_v_at_least(4)) {
81+
echo "API version is 4 or higher. 🚀";
82+
} else {
83+
echo "API version is below 4. Please upgrade.";
84+
}
85+
```
86+
87+
---
88+
89+
### 🌐 . `is_api_request()`
90+
91+
Determines whether the current request is an API request by examining the URL, expected JSON responses, and the presence of specific API headers.
92+
93+
```php
94+
if (is_api_request()) {
95+
echo "This is an API request. 🌐";
96+
} else {
97+
echo "This is not an API request.";
98+
}
99+
```
100+
101+
---
102+
103+
### 📡 . `get_client_ip()`
104+
105+
Retrieves the client's IP address from the current request.
106+
107+
```php
108+
$clientIp = get_client_ip();
109+
echo "Client IP: " . ($clientIp ?? "unknown");
110+
```
111+
112+
---
113+
114+
### 🌍 . `get_request_locale()`
115+
116+
Gets the locale from the request's `Accept-Language` header. If not provided, it defaults to the application's locale.
117+
118+
```php
119+
$locale = get_request_locale();
120+
echo "Request locale: {$locale}";
121+
```
122+
123+
---
124+
125+
### 🔑 . `get_request_token()`
126+
127+
Returns the bearer token from the current request's authorization header.
128+
129+
```php
130+
$token = get_request_token();
131+
echo $token ? "Token: {$token}" : "No token found.";
132+
```
133+
134+
---
135+
136+
### 📝 . `get_request_content_type()`
137+
138+
Retrieves the `Content-Type` header from the current request.
139+
140+
```php
141+
$contentType = get_request_content_type();
142+
echo $contentType ? "Content-Type: {$contentType}" : "No Content-Type provided.";
143+
```
144+
145+
---
146+
147+
### 🔒 . `is_secure_request()`
148+
149+
Checks whether the current request is made over a secure HTTPS connection.
150+
151+
```php
152+
if (is_secure_request()) {
153+
echo "Secure HTTPS request detected. 🔒";
154+
} else {
155+
echo "This is not a secure request.";
156+
}
157+
```
158+
159+
---
160+
161+
### 📋 . `get_request_headers()`
162+
163+
Returns all headers from the current request as an associative array.
164+
165+
```php
166+
$headers = get_request_headers();
167+
print_r($headers); // Displays all request headers
168+
```
169+
170+
---
171+
172+
### 🔐 . `is_api_authenticated()`
173+
174+
Determines whether the API user is authenticated using the `api` guard.
175+
176+
```php
177+
if (is_api_authenticated()) {
178+
echo "API user is authenticated. 🔐";
179+
} else {
180+
echo "API user is not authenticated.";
181+
}
182+
```
183+
184+
---
185+
186+
### 👤 . `get_auth_user()`
187+
188+
Retrieves the authenticated user from the default authentication guard.
189+
190+
```php
191+
$user = get_auth_user();
192+
echo $user ? "Authenticated user: {$user->name}" : "No authenticated user.";
193+
```
194+
195+
---
196+
197+
### 👥 . `get_api_user()`
198+
199+
Returns the authenticated user using the `api` guard.
200+
201+
```php
202+
$apiUser = get_api_user();
203+
echo $apiUser ? "API User: {$apiUser->name}" : "No API user authenticated.";
204+
```
205+
206+
---
207+
208+
## Changelog
209+
210+
See [CHANGELOG](CHANGELOG.md) for recent changes.
211+
212+
## Contributors ✨
213+
214+
Thanks to these wonderful people for contributing to this project! 💖
215+
216+
<table>
217+
<tr>
218+
<td align="center">
219+
<a href="https://github.com/omaralalwi">
220+
<img src="https://avatars.githubusercontent.com/u/25439498?v=4" width="100px;" alt="Omar Al Alwi"/>
221+
<br />
222+
<sub><b>Omar Al Alwi</b></sub>
223+
</a>
224+
<br />
225+
🏆 Creator
226+
</td>
227+
</tr>
228+
</table>
229+
230+
Want to contribute? Check out the [contributing guidelines](./CONTRIBUTING.md) and submit a pull request! 🚀
231+
232+
233+
## Security
234+
235+
If you discover any security-related issues, please email `omaralwi2010@gmail.com`.
236+
237+
## Credits
238+
239+
- [Omar Alalwi](https://github.com/omaralalwi)
240+
241+
## License
242+
243+
The MIT License (MIT). See [LICENSE](LICENSE.md) for more information.
244+
245+
246+
---
247+
248+
## 📚 Helpful Open Source Packages & Projects
249+
250+
### Packages
251+
252+
- <a href="https://github.com/omaralalwi/lexi-translate"><img src="https://raw.githubusercontent.com/omaralalwi/lexi-translate/master/public/images/lexi-translate-banner.jpg" width="26" height="26" style="border-radius:13px;" alt="lexi translate" /> Lexi Translate </a> simplify managing translations for multilingual Eloquent models with power of morph relationships and caching .
253+
254+
- <a href="https://github.com/omaralalwi/Gpdf"><img src="https://raw.githubusercontent.com/omaralalwi/Gpdf/master/public/images/gpdf-banner-bg.jpg" width="26" height="26" style="border-radius:13px;" alt="Gpdf" /> Gpdf </a> Open Source HTML to PDF converter for PHP & Laravel Applications, supports Arabic content out-of-the-box and other languages.
255+
256+
- <a href="https://github.com/omaralalwi/laravel-taxify"><img src="https://raw.githubusercontent.com/omaralalwi/laravel-taxify/master/public/images/taxify.jpg" width="26" height="26" style="border-radius:13px;" alt="laravel Taxify" /> **laravel Taxify** </a> Laravel Taxify provides a set of helper functions and classes to simplify tax (VAT) calculations within Laravel applications.
257+
258+
- <a href="https://github.com/omaralalwi/laravel-api-helpers"><img src="https://raw.githubusercontent.com/omaralalwi/laravel-api-helpers/master/public/images/laravel-api-helpers.jpg" width="26" height="26" style="border-radius:13px;" alt="laravel Taxify" /> **laravel API Helpers** </a> Laravel API Helpers provides a set of helper of helpful helper functions for API Requests ..
259+
260+
- <a href="https://github.com/omaralalwi/laravel-deployer"><img src="https://raw.githubusercontent.com/omaralalwi/laravel-deployer/master/public/images/deployer.jpg" width="26" height="26" style="border-radius:13px;" alt="laravel Deployer" /> **laravel Deployer** </a> Streamlined Deployment for Laravel and Node.js apps, with Zero-Downtime and various environments and branches.
261+
262+
- <a href="https://github.com/omaralalwi/laravel-trash-cleaner"><img src="https://raw.githubusercontent.com/omaralalwi/laravel-trash-cleaner/master/public/images/laravel-trash-cleaner.jpg" width="26" height="26" style="border-radius:13px;" alt="laravel Trash Cleaner" /> **laravel Trash Cleaner** </a> clean logs and debug files for debugging packages.
263+
264+
- <a href="https://github.com/omaralalwi/laravel-time-craft"><img src="https://raw.githubusercontent.com/omaralalwi/laravel-time-craft/master/public/images/laravel-time-craft.jpg" width="26" height="26" style="border-radius:13px;" alt="laravel Time Craft" /> **laravel Time Craft** </a> simple trait and helper functions that allow you, Effortlessly manage date and time queries in Laravel apps.
265+
266+
- <a href="https://github.com/omaralalwi/php-builders"><img src="https://repository-images.githubusercontent.com/917404875/c5fbf4c9-d41f-44c6-afc6-0d66cf7f4c4f" width="26" height="26" style="border-radius:13px;" alt="PHP builders" /> **PHP builders** </a> sample php traits to add ability to use builder design patterns with easy in PHP applications.
267+
268+
- <a href="https://github.com/omaralalwi/php-py"> <img src="https://avatars.githubusercontent.com/u/25439498?v=4" width="26" height="26" style="border-radius:13px;" alt="PhpPy - PHP Python" /> **PhpPy - PHP Python** </a> Interact with python in PHP applications.
269+
270+
- <a href="https://github.com/omaralalwi/laravel-py"><img src="https://avatars.githubusercontent.com/u/25439498?v=4" width="26" height="26" style="border-radius:13px;" alt="Laravel Py - Laravel Python" /> **Laravel Py - Laravel Python** </a> interact with python in Laravel applications.
271+
272+
- <a href="https://github.com/deepseek-php/deepseek-php-client"><img src="https://avatars.githubusercontent.com/u/193405629?s=200&v=4" width="26" height="26" style="border-radius:13px;" alt="Deepseek PHP client" /> **deepseek PHP client** </a> robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities .
273+
274+
- <a href="https://github.com/deepseek-php/deepseek-laravel"><img src="https://github.com/deepseek-php/deepseek-laravel/blob/master/public/images/laravel%20deepseek%20ai%20banner.jpg?raw=true" width="26" height="26" style="border-radius:13px;" alt="deepseek laravel" /> **deepseek laravel** </a> Laravel wrapper for Deepseek PHP client to seamless deepseek AI API integration with Laravel applications.
275+
276+
- <a href="https://github.com/qwen-php/qwen-php-client"><img src="https://avatars.githubusercontent.com/u/197095442?s=200&v=4" width="26" height="26" style="border-radius:13px;" alt="Qwen PHP client" /> **Qwen PHP client** </a> robust and community-driven PHP client library for seamless integration with the Qwen API .
277+
278+
- <a href="https://github.com/qwen-php/qwen-laravel"><img src="https://github.com/qwen-php/qwen-laravel/blob/master/public/images/laravel%20qwen%20ai%20banner.jpg?raw=true" width="26" height="26" style="border-radius:13px;" alt="qwen laravel" /> **Laravel qwen** </a> wrapper for qwen PHP client to seamless Alibaba qwen AI API integration with Laravel applications..
279+
280+
### Dashboards
281+
282+
- <a href="https://github.com/omaralalwi/laravel-startkit"><img src="https://raw.githubusercontent.com/omaralalwi/laravel-startkit/master/public/screenshots/backend-rtl.png" width="26" height="26" style="border-radius:13px;" alt="Laravel Startkit" /> **Laravel Startkit** </a> Laravel Admin Dashboard, Admin Template with Frontend Template, for scalable Laravel projects.
283+
284+
- <a href="https://github.com/kunafaPlus/kunafa-dashboard-vue"><img src="https://github.com/kunafaPlus/kunafa-dashboard-vue/raw/master/public/screenshots/Home-LTR.png" width="26" height="26" style="border-radius:13px;" alt="Kunafa Dashboard Vue" /> **Kunafa Dashboard Vue** </a> A feature-rich Vue.js 3 dashboard template with multi-language support and full RTL/LTR bidirectional layout capabilities.
285+
286+
### References
287+
288+
- <a href="https://github.com/omaralalwi/clean-code-summary"><img src="https://avatars.githubusercontent.com/u/25439498?v=4" width="26" height="26" style="border-radius:13px;" alt="Clean Code Summary" /> **Clean Code Summary** </a> summarize and notes for books and practices about clean code.
289+
290+
- <a href="https://github.com/omaralalwi/solid-principles-summary"><img src="https://avatars.githubusercontent.com/u/25439498?v=4" width="26" height="26" style="border-radius:13px;" alt="SOLID Principles Summary" /> **SOLID Principles Summary** </a> summarize and notes for books about SOLID Principles.

command

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
composer require omaralalwi/laravel-api-helpers

0 commit comments

Comments
 (0)