hitesh399 / laravel-media
该软件包最新版本(v1.0.1)没有可用的许可信息。
Laravel Media Popup 用于上传/查看文件
v1.0.1
2018-09-20 06:19 UTC
Requires
- laravel/framework: 5.*
- laravelcollective/html: 5.*
This package is auto-updated.
Last update: 2024-09-11 19:36:36 UTC
README
composer require hitesh399/laravel-media
将提供者添加到 config/app.php 文件中
Collective\Html\HtmlServiceProvider::class,
Hitesh399\LaravelMedia\LaravelMediaServiceProvider::class,
在 config/app.php 文件中添加别名
'Form' => Collective\Html\FormFacade::class,
'Html' => Illuminate\Support\Facades\Html::class,
要发布供应商和更新数据库模式,您可以执行以下命令:(您还需要安装 node 和 npm)
php artisan vendor:publish --tag=laravel-media //to publish the vendor
php artisan migrate // update the database schema
npm install //Download and install the dependency
npm install --save-dev @fortawesome/fontawesome-free //to download font awesome
要编译媒体文件,将以下行添加到 webpack.mix.js 文件中
require('./laravel.media.webpack.mix');
要生成脚本/css,执行以下提到的命令
npm run dev
在 .env 文件中将文件系统驱动器
FILESYSTEM_DRIVER=public //file driver for upload the data
按以下所示配置 config/filesystems.php
'public' => [
'driver' => 'local',
'root' => public_path('storage'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
要创建存储链接,执行以下提到的命令
php artisan storage:link
通过在 head 标签之间添加以下脚本定义全局变量
<script type="text/javascript">
window.site = {
'site_url':'{!!url('/')!!}',
'base_url':'{!!asset('/')!!}',
'storage_url':'{!!Storage::url('/')!!}',
'admin_url':'{!!url('/admin')!!}',
};
</script>
要使用媒体弹出,包含 jQuery 和 Bootstrap 框架的 css/js 文件,并添加以下提到的脚本文件。
<script type="text/javascript" src="{!!(asset(mix('assets/js/laravel.media.min.js')))!!}"></script>
创建控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\File;
class FileController extends Controller
{
use \Hitesh399\LaravelMedia\Controllers\FileManager;
public function test (Request $request) {
$this->validate($request, [
'test' => 'required'
]);
}
}
在路由文件中添加以下列出的行以定义媒体路由
Route::get('files-manager','FileController@index');
Route::match(['post','get'],'files-uploader','FileController@uploader');
Route::put('make-thumb','FileController@makeThumb');
Route::get('files-list','FileController@getList');
Route::post('test-media-form','FileController@test')->name('laravel.media_test');
要开始使用,在 html 文件中添加以下列出的行
{!!Form::open(array('route' => 'laravel.media_test')) !!}
{!!Form::text('username')!!}
{!!Form::laravelMedia('image')!!}
{!!Form::submit('Click Me!')!!}
{!!Form::close()!!}
如何使用媒体弹出以及如何覆盖功能
使用函数 Form::laravelMedia($name, $label, $data, $listmaker, $htmlrender, $options)
$name [string] -> pass name of element
$label [string] -> pass the lebel of element
$listmaker[string] -> javascript function, to modify the slected file html, the callback function should be define in javascript with four arguments Like:
function listmaker(hiddenFields, file, index, elementName) => HTML
hiddenFields [html] -> contains the html of file hidden fields,
file [Object] -> Object of selected file
index [integer] -> index of selected file
elemengtName [string] -> media field name
Note: in this function you have to renturn the HTMl
$htmlrender [string] -> javascript function, To render the prepare the html by listmaker function, function have the 3 arguments Like:
function htmlrender (html, inputName, element )
html [HTML] -> prepare html by listmaker function
inputName [String] -> media field name
element [Object] instance of the media button which use to open the media popup.
$options [Array] => [
tag [string] -> should be html tag like: button, a, span, and more
tag_class [String] -> define the class name of media button
thumb [Array] => [
[
h [String] -> define the height of thumbnail
w [String] -> define the width of thumbnail
title [String] ->define the title of thumbnail
]
]
title [String] -> Title to diplay on the media popup
selected_btn_text [String] -> Selected button text
close_btn_text [String] -> Close button text
maxFiles [integer] -> Max number of file.
maxFilesize [integer] -> Max size of file in bytes
acceptedFiles [String] -> Accepted file type like: image/*,/png, application/*, .gif
]