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.
Installs: 37
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/agifsofyan/noto
Requires
- intervention/image: ^2.7
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 used
- file_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()