Download the PHP package samsin33/laravel-foundation without Composer
On this page you can find all versions of the php package samsin33/laravel-foundation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download samsin33/laravel-foundation
More information about samsin33/laravel-foundation
Files in samsin33/laravel-foundation
Package laravel-foundation
Short Description This package provide foundation for laravel to use its features more smoothly.
License MIT
Informations about the package laravel-foundation
Introduction
Foundation package for laravel version 9 and 10. This package provide foundation for laravel to use its features more smoothly.
Installation
Just install samsin33/laravel-foundation package with composer.
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.
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
The foundation model performs the below features in very simple way.
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->errors()->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.
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.
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->queue_user attribute.
In the above example lets delete all post comments on queue.
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.
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.
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.
All versions of laravel-foundation with dependencies
ext-json Version *
guzzlehttp/guzzle Version ^7.2
illuminate/log Version ^9.0|^10.0
illuminate/notifications Version ^9.0|^10.0
illuminate/console Version ^9.0|^10.0
illuminate/container Version ^9.0|^10.0
illuminate/contracts Version ^9.0|^10.0
illuminate/database Version ^9.0|^10.0
illuminate/encryption Version ^9.0|^10.0
illuminate/http Version ^9.0|^10.0
illuminate/support Version ^9.0|^10.0