PHPackages                             somarkn99/apibasicsetting - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. somarkn99/apibasicsetting

ActiveLibrary[Framework](/categories/framework)

somarkn99/apibasicsetting
=========================

This package allows you to secure and configure the essentials of your business using the API

1.0.6(3y ago)619MITPHP

Since Oct 8Pushed 3y ago2 watchersCompare

[ Source](https://github.com/somarkn99/api-basic-setting)[ Packagist](https://packagist.org/packages/somarkn99/apibasicsetting)[ RSS](/packages/somarkn99-apibasicsetting/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (8)Used By (0)

API Basic Setting Package
=========================

[](#api-basic-setting-package)

This package allows you to secure and configure the essentials of your business using the API. 😎

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require somarkn99/apibasicsetting
```

Middleware
----------

[](#middleware)

1. AcceptJsonResponse Middleware.

---

It Ensures you will get a response in JSON

```
class AcceptJsonResponse
{
    public function handle($request, Closure $next)
    {
        $request->headers->set('Accept', 'application/json');

        return $next($request);
    }
}
```

2. CORS.

---

In order to avoid getting a CORS Error 😤

```
class CORS
{
    public function handle($request, Closure $next)
    {
        $response = $next($request);
        $response->headers->set('Access-Control-Allow-Origin', '*');
        $response->headers->set('Access-Control-Allow-Methods', '*');
        $response->headers->set('Access-Control-Allow-Credentials', true);
        $response->headers->set('Access-Control-Allow-Headers', 'X-Requested-With,Content-Type,X-Token-Auth,Authorization');

        return $response;
    }
}
```

3. FingerPrintHeader

---

Delete personal information sent with unnecessary requests (in order to increase security) 🔕 🔇

```
class FingerPrintHeader
{
    public function handle($request, Closure $next)
    {
        $request->headers->remove('X-Powered-By');
        $request->headers->remove('Server');

        return $next($request);
    }
}
```

4. Host

---

As an additional security step, applications are not accepted to a specific domain and are pre-defined in the .env file. 🔒 🛡️

- Add this only for your dashboard or frontend app Don't use it for mobile application because it recognize it by Ip address for each user mobile

Note: Local server is accepted by default ✌️

```
class Host
{
    public function handle($request, Closure $next)
    {
        $RequestHost = parse_url(\Illuminate\Support\Facades\URL::full())['host'];
        $AcceptedHost = explode(',', env('ACCEPTED_HOST'));

        if (in_array($RequestHost, $AcceptedHost) == true || $RequestHost == 'localhost') {
            return $next($request);
        } else {
            abort(403);
        }
    }
}
```

You can add more than one domain and be added as follows: in your .env file add this:

```
ACCEPTED_HOST=www.somar-kesen.com,api.somar-kesen.com

```

separated between each domain by ","

5. localization

---

When you work with SPA or Mobile Apps, you do not want to send messages by language other than the user language, for example user language is EN and you send it in Spanish!!

Here you can select the language you want to send to the user, all you need to do is add the language file to the lang folder and add a new item to the array.

From Client side you should send 'X-localization' header, if you don't english will be considered the default language of messages.

```
class localization
{
    public function handle($request, Closure $next)
    {
        // Check header request and determine localization
        $local = ($request->hasHeader('X-localization')) ? $request->header('X-localization') : 'en';

        // set laravel localization
        app()->setLocale($local);

        // continue request
        return $next($request);
    }
}
```

6. SecureCheck

---

You are building apps for many customers but don't know if they will use SSL certificates or not, which may cause some features in your app to break down. For that, this middleware prepares to rejected all requests that don't use https Protocol (Under Development until know)

```
class SecureCheck
{
    public function handle(Request $request, Closure $next)
    {
        if (! $request->secure() && App::environment('production')) {
            return response()->json("Please use https protocol so you can send requests.", Response::HTTP_BAD_REQUEST);
        }

        return $next($request);
    }
}
```

Helpers
-------

[](#helpers)

1. \_dd

---

it's allow you to read the dd value from developer section in your browser.

```
    function _dd(...$args)
    {
        $trace = debug_backtrace();
        $path = '';
        $path .= isset($trace[1]['class']) ? class_basename($trace[1]['class']) : '';
        $path .= isset($trace[1]['function']) ? '@'.$trace[1]['function'].'()' : '';
        $path .= isset($trace[1]['function']) ? ' => line('.$trace[0]['line'].')' : null;

        return response()->json([
            'Path' => $path,
            'dd_Data' => $args,
        ],Response::HTTP_INTERNAL_SERVER_ERROR);
        exit();
    }
```

2. setEnv

---

You can easily adjust the value of the variables in the .env file

```
    function setEnv($key, $value)
    {
        $path = base_path('.env');
        if (file_exists($path)) {
            file_put_contents($path,
                str_replace($key.'='.env($key), $key.'='.$value,
                    str_replace($key.'="'.env($key).'"', $key.'="'.$value.'"',
                        file_get_contents($path))
                ));
        }
    }
```

3. checkIfFileExists

---

This function to check if request has file

```
    function checkIfFileExists($file, $name)
    {
        if (isset(request()->all()[$name])) {
            if (gettype(request()->all()[$name]) !== 'array') {
                if (! isset($file) || is_null($file) || ! request()->hasFile($name)) {
                    return response()->json('please make sure you store correct file.', Response::HTTP_BAD_REQUEST);
                }
            }
        }
    }
```

4. dateFormat

---

It's allow you to format your date in function nested of write it every time for example:

```
$dt = Carbon::create(1975, 12, 25, 14, 15, 16);
echo $dt->toFormattedDateString();                 // Dec 25, 1975

```

```
function dateFormat($date)
{
    return \Carbon\Carbon::parse($date)->toFormattedDateString();
}
```

Note ⚠️
-------

[](#note-warning)

Not all of these codes have to be from my pure work, there are many of them on the Internet that I may have done some but not limited to some modification, improvement, or modification of the appearance of the code to become readable, understandable or appropriate to the place of use. If you have any code you think will be useful and people will use frequently in many projects do not hesitate to do a pull request to this repo.

Let's Connect
-------------

[](#lets-connect)

- [Linkedin](https://www.linkedin.com/in/somarkn99/)
- [website](https://www.somar-kesen.com/)
- [facebook](https://www.facebook.com/SomarKesen)
- [instagram](https://www.instagram.com/somar_kn/)

Hire Me 🔥
---------

[](#hire-me-fire)

By the way, I'm available to work as freelancer, feel free to communicate with me in order to transform your project from an idea to reality.

Security
--------

[](#security)

If you discover any security related issues, please email them first to , if we do not fix it within a short period of time please open a new issue describe your problem.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

7

Last Release

1305d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fe7dcc91c20617cded37a29c62a453957d062954b62ff058f03bece8b5e0bbb6?d=identicon)[somarkn99](/maintainers/somarkn99)

---

Top Contributors

[![somarkn99](https://avatars.githubusercontent.com/u/44697004?v=4)](https://github.com/somarkn99 "somarkn99 (17 commits)")

---

Tags

apilaravelpackagesettingssyriasyrianapiframeworklaravellocalizationcors

### Embed Badge

![Health badge](/badges/somarkn99-apibasicsetting/health.svg)

```
[![Health](https://phpackages.com/badges/somarkn99-apibasicsetting/health.svg)](https://phpackages.com/packages/somarkn99-apibasicsetting)
```

###  Alternatives

[nutgram/nutgram

The Telegram bot library that doesn't drive you nuts

714214.9k8](/packages/nutgram-nutgram)[lanin/laravel-api-debugger

Easily debug your JSON API.

2311.8M](/packages/lanin-laravel-api-debugger)[laravel-lang/common

Easily connect the necessary language packs to the application

1463.1M21](/packages/laravel-lang-common)[lanin/laravel-api-exceptions

All in one solution for exception for JSON REST APIs on Laravel and Lumen.

40102.4k](/packages/lanin-laravel-api-exceptions)[patricksavalle/slim-rest-api

Production-grade REST-API App-class for PHP SLIM, in production on https://zaplog.pro (https://api.zaplog.pro/v1)

101.4k](/packages/patricksavalle-slim-rest-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
