Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/laravelir/attachmentable
A package for attachment files to models
https://github.com/laravelir/attachmentable
eloquent filesystem laravel laravel-attachmentable laravel-model laravel-package laravel-uploader php
Last synced: 7 days ago
JSON representation
A package for attachment files to models
- Host: GitHub
- URL: https://github.com/laravelir/attachmentable
- Owner: laravelir
- Created: 2021-08-23T23:51:21.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-10-21T15:44:57.000Z (about 1 year ago)
- Last Synced: 2024-03-23T16:46:31.072Z (8 months ago)
- Topics: eloquent, filesystem, laravel, laravel-attachmentable, laravel-model, laravel-package, laravel-uploader, php
- Language: PHP
- Homepage:
- Size: 57.6 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
- [![Starts](https://img.shields.io/github/stars/laravelir/attachmentable?style=flat&logo=github)](https://github.com/laravelir/attachmentable/forks)
- [![Forks](https://img.shields.io/github/forks/laravelir/attachmentable?style=flat&logo=github)](https://github.com/laravelir/attachmentable/stargazers)# Laravel attachmentable package
A package for attachment files to models
## Installation
1. Run the command below to add this package:
```
composer require laravelir/attachmentable
```2. Open your config/attachmentable.php and add the following to the providers array:
```php
Laravelir\Attachmentable\Providers\AttachmentableServiceProvider::class,
```3. Run the command below to install package:
```
php artisan attachmentable:install
```4. Run the command below to migrate database:
```
php artisan migrate
```## Uses
First add `Attachmentable` trait to models that you want have attachments
```php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Laravelir\Attachmentable\Traits\Attachmentable;class Post extends Model
{
use HasFactory,
Attachmentable;
}```
and add `Attachmentorable` trait to User models
```php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Laravelir\Attachmentable\Traits\Attachmentorable;class User extends Model
{
use HasFactory,
Attachmentorable;
}```
### Methods
in controllers, with `Attachmentable` trait you have these methods:
```php
namespace App\Http\Controllers;
use App\Models\Post;
class PostController extends Controller
{
public function index()
{
$file = request()->file('thumbnail');
$post = Post::find(1);$post->attach($file, "posts/thumbnails");
$post->attachments // return all attachments
$post->attachment($id); // return attachment
$post->detach($id);
$post->clearAttachments();
}
}```