2017 © Pedro Peláez
 

package ao-files

Resources for Files with Laravel.

image

alex-oliveira/ao-files

Resources for Files with Laravel.

  • Tuesday, May 30, 2017
  • by alex-oliveira
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Ao-Files

1) Installing

$ composer require alex-oliveira/ao-files

2) Configuring "config/app.php" file

'providers' => [
    /*
     * Vendor Service Providers...
     */
    AoFiles\ServiceProvider::class,
],

3) Publish migrations

$ php artisan vendor:publish
$ composer dump

Utilization

Migration

Up

public function up()
{
    AoFiles()->schema()->create('posts');
}

the same that, (*1)

public function up()
{    
    Schema::create('ao_files_x_posts', function (Blueprint $table) {
        $table->integer('post_id')->unsigned();
        $table->foreign('post_id', 'fk_posts_x_ao_files')->references('id')->on('posts');

        $table->bigInteger('file_id')->unsigned();
        $table->foreign('file_id', 'fk_ao_files_x_posts')->references('id')->on('ao_files_files');

        $table->primary(['post_id', 'file_id'], 'pk_ao_files_x_posts');
    });
}

Down

public function down()
{
    AoFiles()->schema()->drop('posts');
}

the same that, (*2)

public function down()
{    
    Schema::dropIfExists('ao_files_x_posts');
}

Model

namespace App\Models;

use AoFiles\Models\File;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{

    /**
     * @return File[]|\Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function files()
    {
        return $this->belongsToMany(File::class, AoFiles()->schema()->table($this->getTable()));
    }

}

the same that, (*3)

return $this->belongsToMany(File::class, 'ao_files_x_posts');

Controller

namespace App\Http\Controllers\Posts;

use AoFiles\Controllers\AoFilesController;
use App\Models\Post;

class FilesController extends AoFilesController
{

    protected $dynamicClass = Post::class;

    protected $subFolders = ['posts' => 'post_id'];

}

Routes

Route::group(['prefix' => 'posts', 'as' => 'posts.'], function () {

    AoFiles()->router()->controller('Posts\FilesController')->foreign('post_id')->make();
    .
    .
    .

});

Checking routes

$ php artisan route:list

The Versions

30/05 2017

dev-master

9999999-dev https://github.com/alex-oliveira/ao-files

Resources for Files with Laravel.

  Sources   Download

MIT

The Requires

 

laravel files alex-oliveira