Commit 5abd4e02 authored by Silvio Gratani's avatar Silvio Gratani

merge master

parents 639c2744 a475153c
......@@ -99,6 +99,22 @@ interface BaseRepository
*/
public function clearCache();
/**
* Add where statement to current builder
*
* @param string $field
* @param string|int $value
* @param string $operator
*/
public function where(string $field, $value, string $operator = null);
/**
* Eager relationship(s) loading
*
* @param array|string $relationships
*/
public function with($relationships);
/**
* @param string $field
* @param array $values
......
......@@ -228,5 +228,24 @@ abstract class BaseCacheDecorator implements BaseRepository
public function whereIn(string $field, array $values)
{
return $this->repository->whereIn($field, $values);
/**
* @inheritdoc
*/
public function where(string $field, $value, string $operator = null)
{
return $this->remember(function () use ($field, $value, $operator) {
return $this->repository->where($field, $value, $operator);
});
}
/**
* @inheritdoc
*/
public function with($relationships)
{
return $this->remember(function () use ($relationships) {
return $this->repository->with($relationships);
});
}
}
......@@ -192,6 +192,28 @@ abstract class EloquentBaseRepository implements BaseRepository
return true;
}
/**
* @inheritdoc
*/
public function where(string $field, $value, string $operator = null)
{
if ($operator === null) {
$operator = '=';
} else {
list($value, $operator) = [$operator, $value];
}
return $this->model->where($field, $operator, $value);
}
/**
* @inheritdoc
*/
public function with($relationships)
{
return $this->model->with($relationships);
}
/**
* @param string $field
* @param array $values
......@@ -200,4 +222,5 @@ abstract class EloquentBaseRepository implements BaseRepository
{
return $this->model->whereIn($field, $values);
}
}
<template>
<div class="row">
<div class="col-xs-12">
<el-upload
class="media-upload"
drag
:action="uploadUrl"
:on-preview="handlePreview"
:on-remove="handleRemove"
:on-success="handleSuccess"
:file-list="fileList"
:headers="requestHeaders"
multiple>
<i class="el-icon-upload"></i>
<div class="el-upload__text">Drop file here or <em>click to upload</em></div>
</el-upload>
</div>
</div>
<el-upload
class="media-upload"
drag
:action="uploadUrl"
list-type="picture"
:show-file-list="false"
:http-request="uploadFile"
multiple
>
<i class="el-icon-upload"></i>
<div class="el-upload__text">Drop file here or <em>click to upload</em></div>
</el-upload>
</template>
<script>
import axios from 'axios';
export default {
props: {
parentId: { type: Number },
},
data() {
return {
fileList: [],
fileIsUploading: false,
};
},
computed: {
uploadUrl() {
return route('api.media.store').domain + route('api.media.store').url;
},
requestHeaders() {
const userApiToken = document.head.querySelector('meta[name="user-api-token"]');
return {
Authorization: `Bearer ${userApiToken.content}`,
};
},
},
methods: {
handleSuccess(response) {
this.$events.emit('fileWasUploaded', response);
this.fileList = [];
uploadFile(event) {
this.fileIsUploading = true;
const data = new FormData();
data.append('parent_id', this.parentId);
data.append('file', event.file);
axios.post(route('api.media.store'), data).then((response) => {
this.$events.emit('fileWasUploaded', response);
this.$message({
type: 'success',
message: this.trans('media.file uploaded'),
});
this.fileIsUploading = false;
}, (error) => {
console.log(error.response.data);
this.fileIsUploading = false;
this.$notify.error({
title: 'Error',
message: error.response.data.errors.file[0],
});
});
},
handlePreview() {},
handleRemove() {},
},
mounted() {},
};
</script>
<style>
.media-upload {
margin-bottom: 10px;
}
.el-upload__input {
display: none !important;
}
.el-upload--text {
display: block;
.el-upload--picture, .el-upload--picture-card {
width: 100%;
height: 175px;
line-height: 100px;
border: none;
}
.el-upload-dragger {
width: 100%;
height: 100%;
}
.media-upload {
margin-bottom: 10px;
.el-upload-dragger .el-upload__text {
position: absolute;
bottom: 0;
width: 100%;
}
.el-upload--text {
display: block;
}
</style>
......@@ -38,6 +38,7 @@ return [
'create resource' => 'Create media',
'edit resource' => 'Edit media',
'destroy resource' => 'Delete media',
'file uploaded' => 'File uploaded successfully',
'file too large' => 'File is too large. Must be below :size MB.',
'some files not moved' => 'Some files were not moved',
'files moved successfully' => 'Files moved successfully',
......
......@@ -123,7 +123,7 @@ class SentinelAuthentication implements Authentication
* @param $permission
* @return bool
*/
public function hasAccess($permission)
public function hasAccess($permission) : bool
{
if (! Sentinel::check()) {
return false;
......@@ -136,7 +136,7 @@ class SentinelAuthentication implements Authentication
* Check if the user is logged in
* @return bool
*/
public function check()
public function check() : bool
{
$user = Sentinel::check();
......@@ -153,14 +153,14 @@ class SentinelAuthentication implements Authentication
*/
public function user()
{
return Sentinel::check();
return Sentinel::getUser();
}
/**
* Get the ID for the currently authenticated user
* @return int
*/
public function id()
public function id() : int
{
$user = $this->user();
......
......@@ -2,6 +2,7 @@
namespace Modules\$MODULE$\Providers;
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
use Illuminate\Support\ServiceProvider;
use Modules\Core\Traits\CanPublishConfiguration;
use Modules\Core\Events\BuildingSidebar;
......@@ -31,6 +32,8 @@ class $MODULE$ServiceProvider extends ServiceProvider
$this->app['events']->listen(LoadingBackendTranslations::class, function (LoadingBackendTranslations $event) {
// append translations
});
$this->registerEloquentFactoriesFrom(__DIR__ . '/../Database/factories');
}
public function boot()
......@@ -54,4 +57,15 @@ class $MODULE$ServiceProvider extends ServiceProvider
{
// add bindings
}
/**
* Register factories.
*
* @param string $path
* @return void
*/
protected function registerEloquentFactoriesFrom($path)
{
$this->app->make(EloquentFactory::class)->load($path);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment