Reference: https://unisharp.github.io/laravel-filemanager/integration
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Laravel Filemanager</title>
<link rel="shortcut icon" type="image/png" href="{{ asset('vendor/laravel-filemanager/img/folder.png') }}">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-6">
<h2>Standalone Image Button</h2>
<div class="input-group">
<span class="input-group-btn">
<a id="lfm" data-input="thumbnail" data-preview="holder" class="btn btn-primary">
<i class="fa fa-picture-o"></i> Choose
</a>
</span>
<input id="thumbnail" class="form-control" type="text" name="filepath">
</div>
<img id="holder" style="margin-top:15px;max-height:100px;">
</div>
</div>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script>
var route_prefix = "{{ url(config('lfm.url_prefix', config('lfm.prefix'))) }}";
</script>
<script>
{!! \File::get(base_path('vendor/unisharp/laravel-filemanager/public/js/lfm.js')) !!}
</script>
<script>
$('#lfm').filemanager('image', {prefix: route_prefix});
</script>
</body>
</html>
in storefunction:
to store thumbnail also:
static function getThumb($path)
{
$str_to_insert = '/thumbs';
$oldstr = $path;
$pos = strrpos($path,"/");
return substr_replace($oldstr, $str_to_insert, $pos, 0);
}
public function store(Request $request)
{
// $request->validate([
// 'banner_image' => 'dimensions:min_width=400,min_height=200',
// ]);
$input = $request->all();
$thumbimage= static::getThumb($request->banner_image);
$input['thumbnail'] = $thumbimage;
...
In blade:
<div class="col-md-4">
<label>Banner Image</label>
<div class="input-group">
<span class="input-group-btn">
<a id="lfm" data-input="thumbnail" data-preview="holder" class="btn btn-primary ">
<i class="fa fa-picture-o"></i> Choose
</a>
</span>
<input id="thumbnail" class="form-control" type="hidden" name="image"
value="{{old('image',$slider->image)}}">
</div>
<img id="holder" style="margin-top:15px; max-height:100px;">
@if(($slider->id!=NULL))
<img src="{{asset($slider->image)}}" height="100" width="150">
@endif
</div>
Script:
<script>
var route_prefix = "{{ url(config('lfm.url_prefix', config('lfm.prefix'))) }}";
{!!\File::get(base_path('vendor/unisharp/laravel-filemanager/public/js/lfm.js')) !!}
$('#lfm').filemanager('image', {
prefix: route_prefix
});
</script>
Comments
Post a Comment