laravelir / attachmentable by miladimos

A package for attachment files to models
18
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-05-01 03:00:20
Package Statistics
Total Downloads: 18
Monthly Downloads: 1
Daily Downloads: 1
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

        
    }
}