baki / gallery
存储画廊
dev-master
2020-09-29 07:51 UTC
Requires
- php: >=7.1.3
- illuminate/config: >=5.8.2
- illuminate/filesystem: >=5.8.2
- illuminate/http: >=5.8.2
- intervention/image: 2.5.1
This package is auto-updated.
Last update: 2024-09-23 15:45:20 UTC
README
使用composer安装此包
composer require baki/gallery
要使用画廊包,在控制器中使用此代码
use StoreGallery;
之后,在config/filesystems.php中创建你的磁盘
'yourDisk' => [
'driver' => 'local',
'root' => storage_path('app/public/your-directory'),
'url' => env('APP_URL').'/your-directory',
'visibility' => 'public',
],
在你的表中必须有'图像'列以及新闻或帖子ID的列。例如
public function up()
{
Schema::create('galleries', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('id_news'); // In my case this is foreign key from table news. This is ID of my news
$table->string('image')->nullable();
$table->timestamps();
});
}
在方法中使用我的包来存储画廊,如下所示
StoreGallery::store('App\YourModel', 'input_name', 'yourDisk', 'id_of_your_post_or_news', 'column_in_database', false, width, height);
存储画廊示例
public function store(Request $r)
{
$news = new News;
$news->title = strip_tags($r->title);
$news->content = strip_tags($r->content);
$news->save();
// It is without crop image
StoreGallery::store('App\Gallery', 'gallery', 'galleryNews', $input->id, 'id_news');
// It is with crop image
StoreGallery::store('App\Gallery', 'gallery', 'galleryNews', $input->id, 'id_news', false, 840, 420);
return redirect()->route('news.index');
}
更新画廊示例
public function update(Request $r, News $news)
{
$news->title = $r->title;
$news->content = $r->content;
$news->save();
// It is without crop image
StoreGallery::store('App\Gallery', 'gallery', 'galleryNews', $input->id, 'id_news', true); // Old gallery will be deleted
// It is with crop image
StoreGallery::store('App\Gallery', 'gallery', 'galleryNews', $input->id, 'id_news', true, 840, 420); // Old gallery will be deleted
return redirect()->route('news.index');
}
要删除画廊,使用此代码
StoreGallery::delete('App\YourModel', $id_news_or_post, 'column_in_database', 'yourDisk');
删除画廊和新闻示例
public function destroy(News $news)
{
StoreGallery::delete('App\Gallery', $news->id, 'id_news', 'galleryNews');
$news->delete();
return redirect()->route('news.index');
}