agifsofyan/noto
最新稳定版本:1.1.5
Composer 安装命令:
composer require agifsofyan/noto
包简介
This is a plugin/package to use the file system from Octobercms to work on laravel. This plugin will be very helpful if you have 2 projects (Laravel & Octobercms) with the same 1 DB.
README 文档
README
Noto is a package intended to help synchronize filesystems between OCTOBERCMS and LARAVEL. By following the octobercms filesystem flow. Package includes:
- file relations
- use of system_files table
- naming the path / disk name of the file
- the naming of the relation model of the OCTOBERCMS model
Requirement
- PHP 8.0.28
- LARAVEL Framework 9.52.5
Dependency
- intervention/image
Installation
Run composer require agifsofyan/noto
Configuration
Run php artisan vendor:publish --provider="Agifsofyan\Noto\Providers\NotoServiceProvider"
Will create :
-
config file
noto.phpin the config folder.<?php return [ 'model_path' => 'App\Models', 'file_table' => 'system_files', 'model_sync' => [ 'User' => 'RainLab\User\Models\User' ], 'extention' => ['jpg', 'jpeg', 'png', 'gif', 'docx', 'xlsx', 'svg', 'pdf'] ];
model_pathis the path of the LARAVEL model usedfile_tableis the database table name for the file to be used. The default for OCTOBERCMS is system_files.model_syncare the registered models. And this is mandatory.- index (left side) of model_sync is the model name of your LARAVEL project.
- the value (right side) of model_sync is the model name of your OCTOBERCMS project.
-
migration file
2023_01_31_000001_Db_System_Files.phpin the database/migrations folder.Run
php artisan migrate
Use
-
Adding
use Agifsofyan\Noto\Traits\NotoMorph;in your model as Traits.Sample:
<?php namespace App\Models; use Agifsofyan\Noto\Traits\NotoMorph; class User { use NotoMorph;
-
Adding file relation using
morphOneNotoin your model if single upload file.Sample:
public function avatar() { return $this->morphOneNoto('avatar'); }
-
Adding file relation using
morphManyNotoin your model if multiple upload file.Sample:
public function avatars() { return $this->morphManyNoto('avatars'); }
-
To Save file use this from your controller after save / update the model data: Sample:
$user->create($data); // To create new data or $user->save(); // To create new data or update the data $field = 'avatar'; $fields = 'avatars'; if($request->hasFile($field) && $request->file($field)->isValid()){ $user->saveOneFile($request->file($field), $field, $user->id); } if($request->hasFile($fields) && $request->file($fields)->isValid()){ $user->saveManyFile($request->file($fields), $fields, $user->id); }
$userfrom your model where themorphOneNotoormorphManyNotorelations are registered.If update data use
$user->save()don't use$user->update(). -
Call the File Url
Call the thumbnail file:
$user?->avatar()?->getThumb(150, 150)
Call the original file:
$user?->avatar()?->getPath()
统计信息
- 总下载量: 37
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-20