Download the PHP package amirsahra/illustrator without Composer
On this page you can find all versions of the php package amirsahra/illustrator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download amirsahra/illustrator
More information about amirsahra/illustrator
Files in amirsahra/illustrator
Package illustrator
Short Description Easy management of image addition and update
License MIT
Informations about the package illustrator
illustrator
Introduction
Easy management of image addition and update
My most important concerns in working with images have been naming and determining where to store them. That's why I decided to develop this package so that any programmer who, like me, is tired of this naming and choosing the directory to save images, can use it and upload an image to the desired directory without additional work.
It also has the ability to update the target image, which means the target image is deleted and the new image is saved. so easily.
After installation, you can easily use illustrator only with the help of corrupting its facade.
Updating images is also very simple as above, and instead of the upload method, we use update with the parameter of the complete directory of the image that we want to update.
Disks
According to the capabilities of Laravel, we have two types of storage disks. public
and local
If we want to access an
image with a URL (such as a user's image, banner, etc.), its disk must be public
, and if we want an image that can only
be downloaded securely (such as invoices, transaction lists, and any image that security is) its disk must be local
.
Installation
-
You can install the package using composer:
-
Add the following class to the providers array in
config/app.php
- You need to add the config file to the config directory. Publish the configuration file:
WARNING
If this command did not publish any files, chances are, the Laratrust service provider hasn't been registered. Try clearing your configuration cache.
And
The Public Disk
To use the public
disk according to the Laravel feature, you need to create a link.
To create the symbolic link, you may use the storage:link Artisan command:
Usage
For example, you have a model name MyImage with these fields
-
configs
In the configuration file, the activation of the options and their default values are determined.
Let's start by config You edit the config file related to the package that is located in the config directory named illustrator with the publish command (which is explained in the installation section).
This is the default value, and if needed,
key | value (default) | Description |
---|---|---|
disk |
public |
You can choose the disk you want. This is the default value, and if needed, you can choose the desired disk when saving the image. Supported Drivers: "local", "public" |
image_path.dir |
illustrator/imgs |
Default directory to save images |
image_path.random_string.length |
10 |
If you want the name of the image to be created by default and include a random string, set this feature to active and set the string length. |
image_path.random_string.is_active |
true |
You can enable and disable this feature. |
image_path.prefix.value |
pre |
If you want the name of the image to be created by default and include a prefix, set this feature to active and set the prefix value. |
image_path.prefix.is_active |
true |
You can enable and disable this feature. |
image_path.postfix.value |
po |
If you want the name of the image to be created by default and include a postfix, set this feature to active and set the postfix value. |
image_path.postfix.is_active |
true |
You can enable and disable this feature. |
-
Facade
You will easily access it with the help of Facade Package. Just use it in the use class.
-
Upload
This method alone is enough to upload the image. Other values, including directory, name, prefix, and extension, if enabled, are taken from the default value set in the configuration.
The input parameter of the method is of type UploadedFile and it is taken from the sent request that contains the image.
The return of this method is the full address of the image that you use to access the image. Note that the return of this method is saved as the address of the image in the database.
Consider this example :
In form
In class or controller method
-
Directory
You can enter your directory. If you want to use the default directory you specified in the config file, you don't need to use this method.
-
Name
Specify the name of the image or by default it will create a random string with the length you specified in the config file.
Note: The name of the image must be without its type and its type is taken from the image file itself, for example, the name imageName.png
is incorrect
-
Disk
You have two modes for the disk: public and local
If you want to access an image with its address, you must select the disk as public.
If you want the image to be protected and only downloadable, select local disk.
Imag access
With the address of the image (which is created when uploading) and the type of disk, the image can be accessed correctly.
If we want the image to be shown on the pages, its disk must be public, and by adding storage/
to the first of that address, the image will be displayed, as in the following example:
If we want the image to be protected and can only be downloaded, select its local disk.
To protected access the image at the address that the disk was local to when it was saved:
-
Combination of methods
All methods can be used together, but the upload method must come last
-
Upload
Updating the images is very simple as above and instead of the upload method, you should use the update with the full directory parameter of the image you want to update.
In this way, the current image is deleted and the new image replaces it namespace App\Http\Controllers;