PHPackages                             samsin33/laravel-foundation - 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. samsin33/laravel-foundation

ActiveLibrary[Framework](/categories/framework)

samsin33/laravel-foundation
===========================

This package provide foundation for laravel to use its features more smoothly.

v1.2.2(2y ago)116MITPHPPHP ^8.0|^8.1

Since Dec 18Pushed 2y ago1 watchersCompare

[ Source](https://github.com/samsin33/laravel-foundation)[ Packagist](https://packagist.org/packages/samsin33/laravel-foundation)[ RSS](/packages/samsin33-laravel-foundation/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (13)Versions (11)Used By (0)

Introduction
------------

[](#introduction)

Foundation package for laravel version 9 and 10. This package provide foundation for laravel to use its features more smoothly.

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

[](#installation)

Just install samsin33/laravel-foundation package with composer.

```
$ composer require samsin33/laravel-foundation
```

Foundation Model
----------------

[](#foundation-model)

This package is developed to use the Eloquent features in most awesome way:
To create model use the foundation:make-model command. This command will also take additional attributes like --controller, etc. which are there in the laravel documentation.

```
$ php artisan foundation:make-model Post
```

The Post model will be created in your app/Models folder which extends the Samsin33\\Foundation\\Models\\BaseModel class.
Samsin33\\Foundation\\Models\\BaseModel class extends the Illuminate\\Database\\Eloquent\\Model class, so you can do all the functionalities of eloquent model.

Importance
----------

[](#importance)

The foundation model performs the below features in very simple way.

Validations
-----------

[](#validations)

To create validations for a model just define function getValidationRules() this should return the validation array.
To define the custom validation messages define function getValidationMessages() which will also return array of validation messages.
To get error messages use Eloquent object errors(), E.g. $post-&gt;errors()-&gt;all().

Sometimes if you do not want to validate data use saveWithoutValidate(). Sometimes we wish to validate some fields conditionally, E.g. password, status, etc. Use setValidationType(), removeValidationType() and isValidationType() in that case.

**Note:** The validation is happening in the saving event, so it will be called every time in the while creating or updating an Eloquent object.

```
use Samsin33\Foundation\Models\BaseModel;

class Post extends BaseModel
{
    protected function getValidationRules(): array
    {
        $arr = [
          'title' => ['required', 'max:255'],
          'description' => ['required']
        ];
        if ($this->isValidationType('check_status')) {
          $arr['status'] = ['required', 'integer'];
        }
        return $arr;
    }

    protected function getValidationMessages(): array
    {
        return [
          'title.required' => 'A title is required',
          'title.max' => 'Title should be maximum of 255 length',
          'description.required' => 'A description is required'
        ];
    }
}

// You can get errors from model objects. In controller function write code:

function save(Request $request) {
    $post = new Post(['title' => $request->title, $request->description]);
    if (some condition) {
      $post->setValidationType('check_status');
    }
    if ($post->save()) {
    } else {
      $post->errors()->all();
      // or
      $post->showErrors();
      // Other validation functions can also apply check laravel validation documentation.
    }
    // If you want to remove any set validation type use
    $post->removeValidationType('check_status');

    // if no validation required then do:
    $post->saveWithoutValidate();
}
```

Events
------

[](#events)

Laravel Eloquent has 14 events which are: retrieved, creating, created, updating, updated, saving, saved, deleting, deleted, trashed, forceDeleted, restoring, restored, and replicating. To use events in model you just need to define the event name followed by Event function. E.g. savingEvent(), updatedEvent(), deletingEvents().

In the \***ing events** the operation will stop if you return false.

**Note:** The validations are happening in the savingEvent() so call the parent::savingEvent() in that and make sure to return false if parent::savingEvent() is false.

```
use Samsin33\Foundation\Models\BaseModel;

class Post extends BaseModel
{
  public function savingEvent()
    {
        if (parent::savingEvent()) {
             // do something
             return $this;
        }
        return false;
    }

    // To delete all comments if the post is deleted
    public function deletedEvent()
    {
        Comment::where('post_id', $this->id)->delete();
    }
}
```

Queue
-----

[](#queue)

If you want to push something to queue call the dispatchQueue(). This function will take 2 arguments 1st is the function name and 2nd is the data array.
You need to define the function by the name given in the 1st argument with $data argument.
If you want to use the current user attributes in that function at the time post delete() is called use $this-&gt;queue\_user attribute.
In the above example lets delete all post comments on queue.

```
use Samsin33\Foundation\Models\BaseModel;

class Post extends BaseModel
{
  // To delete all comments if the post is deleted
    public function deletedEvent()
    {
        $addition_data = ['some_data'];
        $this->dispatchQueue('deletePostComments', $addition_data);
    }

    // This function will be called once the queue is executed.
    public function deletePostComments($data)
    {
        // $data will have $addition_data values
        Comment::where('post_id', $this->id)->delete();
        // To access the current user details at the time post delete() is called use $this->queue_user attribute.
        $user = $this->queue_user;
    }
}
```

Cache
-----

[](#cache)

The CacheTrait contains very useful functions which makes caching very simple.
Suppose there is a Category model where you want to cache the active and inactive categories.
You need to update the $is\_cached, $cache\_fields, $cache\_conditions attributes.

The **$is\_cached** should be set to true if caching needs to be enabled to that model.
The **$cache\_fields** contains the attributes which needs to be fetched in getCache().
And **$cache\_conditions** must be an array where the key of array is the cache key and its value should also be the array which needs to pass in the where condition if the model as in example given below.

```
use Samsin33\Foundation\Models\BaseModel;

class Category extends BaseModel
{
  protected static bool $is_cached = true;
  protected static $cache_fields = ['id', 'name', 'status'];
  protected static $cache_conditions = ['active' => ['status' => 1], 'inactive' => ['status' => 0]];
}

// To get cached values
Category::getCache('active');
Category::getCache('inactive');

// To set cache values
Category::setCache('active');
Category::setAllCache();

// To delete cache values
Category::destroyCache('inactive');
Category::destroyAllCache();

// resetAllCache function will reset all cache_conditions data of model.
Category::resetAllCache();
```

Mail
----

[](#mail)

MailerTrait contains the sendMail() which will send the email. The function will take the following arguments:
$email\_to,
string $view,
string $subject = '', (optional)
array $data = \[\], (optional)
array $cc = \[\], (optional)
array $bcc = \[\], (optional)
int $reset\_email\_from = 0, (optional)
array $attach = \[\], (optional)
array $reply\_to = \[\]. (optional)

In the view file you can access the attributes with $data variable.
$data will contain 2 keys:
**$data\['object'\]** - which contains the model object.
**$data\['other\_data'\]** - contains the value in the above $data argument passed in sendMail().

You can also send the exception email by using function sendExceptionEmail() in which case you need to add the exception\_email key in your mail config file.
The 1st argument take **$exception** variable which can be an array. The **$exception** data will be available in your view file as **$data\['other\_data'\]**.

**Note:** You can use MailerTrait in Exceptions/Handler.php file also to call exception email function.

```
config/mail.php
return [
  'exception_email' => 'email_to_receive_exception@mail.com'
];

Exceptions/Handler.php
$this->reportable(function (Throwable $exception) {
    $this->sendExceptionEmail(['exception' => $exception->getTraceAsString(), 'exception_view_blade_file']);
});
```

Other Traits
------------

[](#other-traits)

Some other useful traits are:
UserSessionTrait
RequestTypeTrait
DateTrait
GuzzleHttpTrait

To get current user details you can use:
currentUser()
currentUserId()

You can check out the other traits to use their functions.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 84.2% 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 ~23 days

Recently: every ~1 days

Total

10

Last Release

1038d ago

PHP version history (2 changes)v1.0.0PHP ^8.0

v1.1.x-devPHP ^8.0|^8.1

### Community

Maintainers

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

---

Top Contributors

[![samarthas](https://avatars.githubusercontent.com/u/26267886?v=4)](https://github.com/samarthas "samarthas (16 commits)")[![samsin33](https://avatars.githubusercontent.com/u/18491431?v=4)](https://github.com/samsin33 "samsin33 (3 commits)")

---

Tags

laravelLaravel BaseLaravel Foundation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/samsin33-laravel-foundation/health.svg)

```
[![Health](https://phpackages.com/badges/samsin33-laravel-foundation/health.svg)](https://phpackages.com/packages/samsin33-laravel-foundation)
```

###  Alternatives

[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k96.9M674](/packages/laravel-socialite)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)

PHPackages © 2026

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