PHPackages                             shankar/laravel-basic-setting - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. shankar/laravel-basic-setting

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

shankar/laravel-basic-setting
=============================

Laravel Basic Setting Package with middleware, traits, and validation rules.

v1.4.2(2mo ago)047MITPHPPHP &gt;=8.1 || &gt;=8.2

Since Aug 15Pushed 2mo agoCompare

[ Source](https://github.com/Shankar-Tom/laravel-basic-setting)[ Packagist](https://packagist.org/packages/shankar/laravel-basic-setting)[ RSS](/packages/shankar-laravel-basic-setting/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (4)Versions (9)Used By (0)

Laravel Basic Setting
=====================

[](#laravel-basic-setting)

A collection of useful traits, middleware, and rules to speed up Laravel development. This package provides helpers for API responses, searching Eloquent models (including relationships), safe Livewire calls, transaction-handling middleware, and a custom phone validation rule.

Features
--------

[](#features)

- **ApiResponse Trait**: Standardized JSON responses for success, error, validation errors, and internal server errors.
- **CanSearch Trait**: Easily add search and relation-search scopes to your Eloquent models.
- **LivewireSafeCallTrait**: Wrap Livewire actions in database transactions with error reporting.
- **HandleWithTransaction Middleware**: Automatically wraps HTTP requests in a DB transaction and handles exceptions gracefully.
- **ValidPhone Rule**: Validate phone numbers with a customizable regex.

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

[](#installation)

1. Install via Composer: ```
    composer require shankar/laravel-basic-setting
    ```
2. (Optional) Publish the middleware to your app: ```
    php artisan vendor:publish --tag=middleware
    ```

Usage
-----

[](#usage)

### ApiResponse Trait

[](#apiresponse-trait)

Use in your controllers to standardize API responses:

```
use Shankar\LaravelBasicSetting\Traits\ApiResponse;

class ExampleController extends Controller {
    use ApiResponse;
    // ...

    public function exampleAction()
    {
        return $this->successResponse(data: 'Example data');
    }
    public function exampleErrorAction()
    {
        return $this->errorResponse(message: 'Example error');
    }

    public function exampleValidationErrorResponse()
    {
        return $this->validationErrorResponse(errors: 'Example validation error');
    }

    public function exampleInternalErrorResponse()
    {
        return $this->internalServerErrorResponse(exception: 'Example internal server error');
    }
}
```

### CanSearch Trait

[](#cansearch-trait)

Add to your Eloquent models for search functionality:

```
use Shankar\LaravelBasicSetting\Traits\CanSearch;

class Post extends Model {
    use CanSearch;
}

// Usage:
Post::search('keyword')->get();
Post::searchRelation('keyword', ['user' => ['name', 'email']])->get();
```

### Lockable Trait

[](#lockable-trait)

Use in your Eloquent models to add a simple lock/unlock feature:

```
use Shankar\LaravelBasicSetting\Traits\Lockable;

class Post extends Model {
    use Lockable;
}
// In your controller

public function editPost(Post $post)
{
    $post->acquireLock();

    // your code
}

public function updatePost(Post $post,Request $request)
{
    // your code for update
    $post->save();
    $post->releaseLock();
}
```

### LivewireSafeDBCallTrait

[](#livewiresafedbcalltrait)

Use in Livewire components to safely wrap actions in transactions:

```
use Shankar\LaravelBasicSetting\Traits\LivewireSafeDBCall;

class ExampleComponent extends Component {
    use LivewireSafeDBCall;
    // ...

    public function exampleAction()
    {
        $this->safeCall(function () {
            // Your code here
        });
    }
}

// Usage in Blade:

    window.addEventListener('livewire-error', event => {
        alert(event.detail.message);
    });

```

### LivewireHandleResetTrait

[](#livewirehandleresettrait)

Use in Livewire components to reset properties:

```
use Shankar\LaravelBasicSetting\Traits\LivewireHandleReset;
use Shankar\LaravelBasicSetting\Attributes\Unresetable;

class ExampleComponent extends Component {
    use LivewireHandleReset;
    // ...
    #[Unresetable]
    public $property1;
    public $property2;

    public function mount()
    {
        $this->property1 = 'value1';
        $this->property2 = 'value2';
    }

    public function exampleAction()
    {
        $this->reset();  // reset only property2
    }
}
```

### LivewireHandleFormTrait

[](#livewirehandleformtrait)

Use in Livewire components to handle form submissions:

```
use Shankar\LaravelBasicSetting\Traits\HandleLivewireForm;

class ExampleComponent extends Component {
    use HandleLivewireForm;
    // ...

    public function exampleAction()
    {
        // Your code here
    }
}

// In bladefile

    // Your code here

```

### HandleWithTransaction Middleware

[](#handlewithtransaction-middleware)

Publish and register the middleware to wrap requests in DB transactions (see Installation step 2).

### Using in Routes

[](#using-in-routes)

Wrap a route or route group in the middleware to enable DB transactions for the entire request:

```
use Shankar\LaravelBasicSetting\Middleware\HandleWithTransaction;

Route::middleware(HandleWithTransaction::class)->group(function () {
    // Your routes here
});
// This middleware will wrap all the routes in a DB transaction and handle exceptions gracefully for your api routes.

// To see the error in normal web (not API):
// 1. Add `HandleWithTransaction` to `kernel.php` middleware array
// 2. Add `HandleWithTransaction` to your route or route group

// In Blade file

@session('error')
    {{ $message }}
@endSession()
```

### ExpectJsonResponse Middleware

[](#expectjsonresponse-middleware)

Publish and register the middleware to wrap requests in DB transactions (see Installation step 2).

### Using in Routes

[](#using-in-routes-1)

Wrap a route or route group in the middleware to enable DB transactions for the entire request:

```
use Shankar\LaravelBasicSetting\Middleware\ExpectJsonResponse;

Route::middleware(ExpectJsonResponse::class)->group(function () {
    // Your routes here
});

// This middleware is set header to reponse as json for all api routes , it auto apply to all api routes containing `api` prefix
```

### ValidPhone Rule

[](#validphone-rule)

Use in your form requests for phone validation:

```
use Shankar\LaravelBasicSetting\Rules\ValidPhone;

$request->validate([
    'phone' => ['required', new ValidPhone],
]);
```

License
-------

[](#license)

MIT

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance87

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

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 ~37 days

Recently: every ~50 days

Total

8

Last Release

65d ago

PHP version history (2 changes)v1.0.0PHP &gt;=8.0

v1.4.1PHP &gt;=8.1 || &gt;=8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/68939188?v=4)[Shankar Gorai](/maintainers/Shankar-Tom)[@Shankar-Tom](https://github.com/Shankar-Tom)

---

Top Contributors

[![Shankar-Tom](https://avatars.githubusercontent.com/u/68939188?v=4)](https://github.com/Shankar-Tom "Shankar-Tom (17 commits)")

### Embed Badge

![Health badge](/badges/shankar-laravel-basic-setting/health.svg)

```
[![Health](https://phpackages.com/badges/shankar-laravel-basic-setting/health.svg)](https://phpackages.com/packages/shankar-laravel-basic-setting)
```

###  Alternatives

[livewire/flux

The official UI component library for Livewire.

9527.8M127](/packages/livewire-flux)[tallstackui/tallstackui

TallStackUI is a powerful suite of Blade components that elevate your workflow of Livewire applications.

725173.0k14](/packages/tallstackui-tallstackui)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M345](/packages/psalm-plugin-laravel)[venturedrake/laravel-crm

A free open source CRM built as a package for laravel projects

43311.2k](/packages/venturedrake-laravel-crm)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)[noerd/noerd

101.4k6](/packages/noerd-noerd)

PHPackages © 2026

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