Package Data | |
---|---|
Maintainer Username: | alex-oliveira |
Package Create Date: | 2017-05-30 |
Package Last Update: | 2017-05-30 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-14 15:13:18 |
Package Statistics | |
---|---|
Total Downloads: | 8 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
$ composer require alex-oliveira/ao-files
'providers' => [
/*
* Vendor Service Providers...
*/
AoFiles\ServiceProvider::class,
],
$ php artisan vendor:publish
$ composer dump
public function up()
{
AoFiles()->schema()->create('posts');
}
the same that
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');
});
}
public function down()
{
AoFiles()->schema()->drop('posts');
}
the same that
public function down()
{
Schema::dropIfExists('ao_files_x_posts');
}
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
return $this->belongsToMany(File::class, 'ao_files_x_posts');
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'];
}
Route::group(['prefix' => 'posts', 'as' => 'posts.'], function () {
AoFiles()->router()->controller('Posts\FilesController')->foreign('post_id')->make();
.
.
.
});
$ php artisan route:list