bek96/album

为Laravelda tuzilgan web saytlar için Album nesnesi.

v1.0.1 2021-11-19 12:44 UTC

This package is auto-updated.

Last update: 2024-09-21 11:26:31 UTC


README

Latest Version on Packagist Quality Score Total Downloads

安装

使用Composer进行安装。

$ composer require bek96/album

要复制配置文件,请执行以下命令。

php artisan vendor:publish --provider="Bek96\Album\AlbumServiceProvider"

迁移Album和Image模型表。

php artisan migrate

使用方法。

<?php

namespace App;

use Bek96\Album\Traits\HasAlbum;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasAlbum;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

获取专辑主图。

   $user->album->image->path

更改专辑主图

   $file   = $request->image;
   $user->album->setImageAsCover($file);

可以获取以下尺寸的主图。

$user->album->image->xl->path   1920xauto yoki autox1920    
$user->album->image->lg->path   1024xauto yoki autox1024
$user->album->image->md->path   512xauto yoki autox512
$user->album->image->sm->path   256xauto yoki autox256
$user->album->image->xs->path   128xauto yoki autox128
$user->album->image->sp->path   config fayldan o'qiydi x auto yoki autox64

获取专辑中的所有图片。

$user->album->images Rasmlar listini qaytaradi.

Image:
    -   path
    -   xl() : hasOne Image|null
    -   lg() : hasOne Image|null
    -   md() : hasOne Image|null
    -   sm() : hasOne Image|null
    -   xs() : hasOne Image|null
    -   sp() : hasOne Image|null

向专辑中添加新图片。

$file   =   $request->image;
$user->album->addImage($file);      

从专辑中移除图片。

$user->album->removeImage($id) 

需要删除的图片ID