Download the PHP package movor/laravel-custom-casts without Composer

On this page you can find all versions of the php package movor/laravel-custom-casts. 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 laravel-custom-casts

Laravel Custom Casts

Build Downloads Stable License

Make your own custom cast type for Laravel model attributes

By default, from version 5 Laravel supports attribute casting. If we define $cast property on our model, Laravel will help us convert defined attributes to common data types. Currently supported cast types (Laravel 5.6) are: integer, real, float, double, string, boolean, object, array, collection, date, datetime and timestamp.

If those default cast types are not enough and you want to make your own, you'r on the right track.


:heavy_exclamation_mark::heavy_exclamation_mark::heavy_exclamation_mark: MOVING GIT REPOSITORY :heavy_exclamation_mark::heavy_exclamation_mark::heavy_exclamation_mark:

This package repo and maintenance will continue on:

vkovic/laravel-custom-casts.

:truck: :truck: :truck: :truck: :truck: :truck: :truck: :truck: :truck: :truck: :truck: :truck: :truck: :truck: :truck:


Compatibility

The package is compatible with Laravel versions >= 5.1

Installation

Install the package via composer:

Example: Casting User Image

When saving an image, there is two things that needs to be done:

  1. Save image name (sometimes with path) into corresponding database field
  2. Save image physically on the disk

As a guidance for this example we'll use default Laravel user model found in app/User.php.

Beside basic, predefined fields: name, email and password, we also want to allow user to upload his avatar. Assume that we already have users table with image field (you should create seeder for this).

To utilize custom casts, we'll need to add trait to user model, and via $casts property link it to the cast class.

Next step is to create class that'll handle casting. It must implement setAttribute method which will take care of saving the image (from UploadedFile object, via form upload in this case) and generating image name with path - to be preserved in database.

Let's jump to user creation example. This will trigger our custom cast logic.

Assume that we have user controller which will handle user creation. You should create this on your own.

Code below is just a simple example and should be used as guidance only.

Visit corresponding route input basic details and attach the image. After that, we'll have our user created and image stored.

But we should also handle deleting image when user is deleted. This can be accomplished by utilizing underlying eloquent events handling. Each time eloquent event is fired, logic will look up for public method with the same name in our custom cast class.

Possible method names are: retrieved, creating, created, updating, updated, saving, saved, deleting, deleted, restoring and restored.

This should cover basics usage of custom casts.


All versions of laravel-custom-casts with dependencies

PHP Build Version
Package Version
Requires laravel/framework Version 5.5.*|5.6.*|5.7.*
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 movor/laravel-custom-casts contains the following files

Loading the files please wait ....