Skip to content

Instantly share code, notes, and snippets.

@mitrallex
mitrallex / computed-pages
Created February 4, 2018 20:58
laravel-file-hosting
computed: {
pages() {
let pages = [];
let from = this.pagination.current_page - Math.floor(this.offset / 2);
if (from < 1) {
from = 1;
}
@mitrallex
mitrallex / file-is-document
Created February 4, 2018 19:45
laravel-file-hosting
<div v-if="file.type == 'document'" class="document_block">
<figure class="image is-4by3">
<img src="{{ asset('images/document.png') }}" alt="Audio image" id="audio_image">
</figure>
<a class="button is-primary" href="" :href="'{{ asset('storage/' . Auth::user()->name . '_' . Auth::id()) }}' + '/' + file.type + '/' + file.name + '.' + file.extension" target="_blank">
<i class="fa fa-download" aria-hidden="true"></i>
&nbsp;Download
</a>
</div>
@mitrallex
mitrallex / file-is-video
Created February 4, 2018 19:44
laravel-file-hosting
<div v-if="file.type == 'video'" class="video_block">
<video controls>
<source src="" :src="'{{ asset('storage/' . Auth::user()->name . '_' . Auth::id()) }}' + '/' + file.type + '/' + file.name + '.' + file.extension" :type="'video/' + file.extension">
Your browser does not support the video tag.
</video>
</div>
@mitrallex
mitrallex / file-is-audio
Last active February 4, 2018 19:44
laravel-file-hosting
<div v-if="file.type == 'audio'">
<figure class="image is-4by3">
<img src="{{ asset('images/music.png') }}" alt="Audio image" id="audio_image">
</figure>
<audio controls>
<source src="" :src="'{{ asset('storage/' . Auth::user()->name . '_' . Auth::id()) }}' + '/' + file.type + '/' + file.name + '.' + file.extension" :type="'audio/' + file.extension">
Your browser does not support the audio tag.
</audio>
</div>
@mitrallex
mitrallex / file-is-image
Created February 4, 2018 19:42
laravel-file-hosting
<figure class="image is-4by3" v-if="file.type == 'image'" @click="showModal(file)">
<img src="" :src="'{{ asset('storage/' . Auth::user()->name . '_' . Auth::id()) }}' + '/' + file.type + '/' + file.name + '.' + file.extension" :alt="file.name">
</figure>
@mitrallex
mitrallex / card-content
Created February 4, 2018 19:32
laravel-file-hosting
<div class="card-content">
<div class="content">
<p v-if="file !== editingFile" @dblclick="editFile(file)" :title="'Double click for editing filename'">
@{{ file.name + '.' + file.extension}}
</p>
<input class="input" v-if="file === editingFile" v-autofocus @keyup.enter="endEditing(file)" @blur="endEditing(file)" type="text" :placeholder="file.name" v-model="file.name">
<time datetime="2016-1-1">@{{ file.created_at }}</time>
</div>
</div>
@mitrallex
mitrallex / destroyAction.php
Created February 2, 2018 19:35
laravel-file-hosting
if (Storage::disk('local')->exists('/public/' . $this->getUserDir() . '/' . $file->type . '/' . $file->name . '.' . $file->extension)) {
if (Storage::disk('local')->delete('/public/' . $this->getUserDir() . '/' . $file->type . '/' . $file->name . '.' . $file->extension)) {
return response()->json($file->delete());
}
}
@mitrallex
mitrallex / editAction.php
Last active February 2, 2018 19:34
laravel-file-hosting
if (Storage::disk('local')->exists($old_filename)) {
if (Storage::disk('local')->move($old_filename, $new_filename)) {
$file->name = $request['name'];
return response()->json($file->save());
}
}
@mitrallex
mitrallex / storage-file.php
Created February 2, 2018 18:51
laravel-file-hosting
if (Storage::putFileAs('/public/' . $this->getUserDir() . '/' . $type . '/', $file, $request['name'] . '.' . $ext)) {
return $model::create([
'name' => $request['name'],
'type' => $type,
'extension' => $ext,
'user_id' => Auth::id()
]);
}
@mitrallex
mitrallex / file-validation.php
Created February 2, 2018 17:19
larave-file-hosting
$this->validate($request, [
'name' => 'required|unique:files',
'file' => 'required|file|mimes:' . $all_ext . '|max:' . $max_size
]);