Download the PHP package asdh/save-model without Composer

On this page you can find all versions of the php package asdh/save-model. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package save-model

Save Model

Save Model is a Laravel package that allows you to save data in the database in a new way. No need to worry about $guarded and $fillable properties in the model anymore. Just relax an use Save Model package.


Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads


Installation

You can install the package via composer:

You can publish the config file with:

This is the contents of the published config file:

Usage

You just do this and a new user will be created and saved to the 'users' table. The password will be automatically hashed, and uploading of the image will also be automatically handled.

To update a model, you just have to pass the model that you want to update.

Only name and email will be updated and no other columns will be touched.

For this to work, you need to do these things:

Go to User model class or any other model class and add CanBeSavedContract class to it. In this example, I will use User model.

After adding this, you need to add saveableFields method to the User model and map every columns of the users table like so:

After doing this you are good to go. In the controller, you just need to get the data and use the SaveModel class

The files will be uploaded using the default Laravel's filesystem. Which means that you can directly configure to upload the files directly to the S3 as well or any other that Laravel supports.

Also, the files will be uploaded to the files directory by default. You can change that globally by changing the value of file_upload_directory on the save_model.php configuration file.

You can also change it per model like so:

It will now store the image of the user to the images directory and for every other Models, it will use from the save_model.php config file.

You can also, choose the Laravel Filesystem's disk per model like so:

By default random name will be generated for the uploaded files, but you can change that also. You just have to pass closure on the setFileName method and you will get access to the uploaded file there. And whatever you return from here will be saved to the database as the file name.

This example shows how to return the original file name.

If you want to upload the file as the original name then you can do this:

One thing to keep in mind that the setFileName method will take precedence over uploadAsOriginalName if both methods are being used.

Not only this, the deletion of the file will also be automatically handled when updating a model. By default, when a model is updated, the old file will be automatically deleted if a new file is being uploaded. If you don't want the old images to be deleted then you can chain dontDeleteOldFileOnUpdate method.

Available Fields

Other field will be added in the future and I am open to pull requests.

Creating your own model field class

You can create your own field class as well. To create one, you need to run an artisan command

This will create a BooleanField class inside App\ModelFields directory and it will look like this:

It is not necessary that BooleanField class must be inside App\ModelFields directory. You can place it wherever you like.

You will have access to the data passed from the controller as $this->value. Then you can do whatever you want to do and return the value that you want to save in the database. In above case, we can do it like so:

If the input is any one of these, then we will consider it to be true and for every one of these values, we will save true (which will be 1 when stored in database) to the database.

Then you can easily use your own field in the model's saveableFields method. You can now use this BooleanField along with other fields like this:

Make sure you add the namespace correctly as shown above.

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.


All versions of save-model with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
spatie/laravel-package-tools Version ^1.4.3
illuminate/contracts Version ^8.37
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package asdh/save-model contains the following files

Sorry, there are no file data to show!