laravelir / attachmentable by miladimos

A package for attachment files to models
23
4
2
Package Data
Maintainer Username: miladimos
Maintainer Contact: miladimos@outlook.com (miladimos)
Package Create Date: 2021-08-23
Package Last Update: 2023-10-21
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-12-12 15:00:37
Package Statistics
Total Downloads: 23
Monthly Downloads: 1
Daily Downloads: 0
Total Stars: 4
Total Watchers: 2
Total Forks: 1
Total Open Issues: 0
  • Starts
  • Forks

Laravel attachmentable package

A package for attachment files to models

Installation

  1. Run the command below to add this package:
composer require laravelir/attachmentable
  1. Open your config/attachmentable.php and add the following to the providers array:
Laravelir\Attachmentable\Providers\AttachmentableServiceProvider::class,
  1. Run the command below to install package:
php artisan attachmentable:install

Uses

First add Attachmentable trait to models that you want have attachments


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;
}

Methods

in controllers you have these methods:


namespace App\Http\Controllers;

use App\Models\Post;

class PostController extends Controller
{
    public function index()
    {
        $post = Post::find(1);

        $post->attachments // return all attachments

        
    }
}