Improve user photos
This commit is contained in:
parent
8fbfa66059
commit
4df1434f02
6 changed files with 1118 additions and 668 deletions
|
@ -6,11 +6,9 @@ use Inertia\Inertia;
|
||||||
use League\Glide\Server;
|
use League\Glide\Server;
|
||||||
use Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\URL;
|
|
||||||
use Illuminate\Pagination\UrlWindow;
|
use Illuminate\Pagination\UrlWindow;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Date;
|
use Illuminate\Support\Facades\Date;
|
||||||
use Illuminate\Support\Facades\Config;
|
|
||||||
use Illuminate\Support\Facades\Request;
|
use Illuminate\Support\Facades\Request;
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
@ -69,7 +67,7 @@ class AppServiceProvider extends ServiceProvider
|
||||||
'source' => Storage::getDriver(),
|
'source' => Storage::getDriver(),
|
||||||
'cache' => Storage::getDriver(),
|
'cache' => Storage::getDriver(),
|
||||||
'cache_folder' => '.glide-cache',
|
'cache_folder' => '.glide-cache',
|
||||||
'base_url' => URL::to('img'),
|
'base_url' => 'img',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace App;
|
||||||
|
|
||||||
use League\Glide\Server;
|
use League\Glide\Server;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
|
use Illuminate\Support\Facades\URL;
|
||||||
use Illuminate\Auth\Authenticatable;
|
use Illuminate\Auth\Authenticatable;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
@ -36,11 +37,9 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
||||||
|
|
||||||
public function photoUrl(array $attributes)
|
public function photoUrl(array $attributes)
|
||||||
{
|
{
|
||||||
if (!$this->photo_path) {
|
if ($this->photo_path) {
|
||||||
return;
|
return URL::to(App::make(Server::class)->fromPath($this->photo_path, $attributes));
|
||||||
}
|
}
|
||||||
|
|
||||||
return App::make(Server::class)->fromPath($this->photo_path, $attributes)->url();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeOrderByName($query)
|
public function scopeOrderByName($query)
|
||||||
|
|
1717
package-lock.json
generated
1717
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -45,12 +45,12 @@ export default {
|
||||||
return {
|
return {
|
||||||
sending: false,
|
sending: false,
|
||||||
form: {
|
form: {
|
||||||
first_name: '',
|
first_name: null,
|
||||||
last_name: '',
|
last_name: null,
|
||||||
email: '',
|
email: null,
|
||||||
password: '',
|
password: null,
|
||||||
owner: false,
|
owner: false,
|
||||||
photo: '',
|
photo: null,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -59,12 +59,12 @@ export default {
|
||||||
this.sending = true
|
this.sending = true
|
||||||
|
|
||||||
var data = new FormData()
|
var data = new FormData()
|
||||||
data.append('first_name', this.form.first_name)
|
data.append('first_name', this.form.first_name || '')
|
||||||
data.append('last_name', this.form.last_name)
|
data.append('last_name', this.form.last_name || '')
|
||||||
data.append('email', this.form.email)
|
data.append('email', this.form.email || '')
|
||||||
data.append('password', this.form.password)
|
data.append('password', this.form.password || '')
|
||||||
data.append('owner', this.form.owner ? '1' : '0')
|
data.append('owner', this.form.owner ? '1' : '0')
|
||||||
data.append('photo', this.form.photo)
|
data.append('photo', this.form.photo || '')
|
||||||
|
|
||||||
this.$inertia.post(this.route('users.store'), data)
|
this.$inertia.post(this.route('users.store'), data)
|
||||||
.then(() => this.sending = false)
|
.then(() => this.sending = false)
|
||||||
|
|
|
@ -63,7 +63,7 @@ export default {
|
||||||
email: this.user.email,
|
email: this.user.email,
|
||||||
password: this.user.password,
|
password: this.user.password,
|
||||||
owner: this.user.owner,
|
owner: this.user.owner,
|
||||||
photo: '',
|
photo: null,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -72,16 +72,22 @@ export default {
|
||||||
this.sending = true
|
this.sending = true
|
||||||
|
|
||||||
var data = new FormData()
|
var data = new FormData()
|
||||||
data.append('first_name', this.form.first_name)
|
data.append('first_name', this.form.first_name || '')
|
||||||
data.append('last_name', this.form.last_name)
|
data.append('last_name', this.form.last_name || '')
|
||||||
data.append('email', this.form.email)
|
data.append('email', this.form.email || '')
|
||||||
data.append('password', this.form.password)
|
data.append('password', this.form.password || '')
|
||||||
data.append('owner', this.form.owner ? '1' : '0')
|
data.append('owner', this.form.owner ? '1' : '0')
|
||||||
data.append('photo', this.form.photo)
|
data.append('photo', this.form.photo || '')
|
||||||
data.append('_method', 'put')
|
data.append('_method', 'put')
|
||||||
|
|
||||||
this.$inertia.post(this.route('users.update', this.user.id), data)
|
this.$inertia.post(this.route('users.update', this.user.id), data)
|
||||||
.then(() => this.sending = false)
|
.then(() => {
|
||||||
|
this.sending = false
|
||||||
|
if (Object.keys(this.$page.errors).length === 0) {
|
||||||
|
this.form.photo = null
|
||||||
|
this.form.password = null
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
destroy() {
|
destroy() {
|
||||||
if (confirm('Are you sure you want to delete this user?')) {
|
if (confirm('Are you sure you want to delete this user?')) {
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
<div>
|
<div>
|
||||||
<label v-if="label" class="form-label">{{ label }}:</label>
|
<label v-if="label" class="form-label">{{ label }}:</label>
|
||||||
<div class="form-input p-0" :class="{ error: errors.length }">
|
<div class="form-input p-0" :class="{ error: errors.length }">
|
||||||
<input class="hidden" ref="file" type="file" @change="change" :accept="accept">
|
<input ref="file" type="file" :accept="accept" class="hidden" @change="change">
|
||||||
<div v-if="!value" class="p-2">
|
<div v-if="!value" class="p-2">
|
||||||
<button @click="browse" type="button" class="px-4 py-1 bg-grey-dark hover:bg-grey-darker rounded-sm text-xs font-medium text-white">
|
<button type="button" class="px-4 py-1 bg-grey-dark hover:bg-grey-darker rounded-sm text-xs font-medium text-white" @click="browse">
|
||||||
Browse
|
Browse
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="flex items-center justify-between p-2">
|
<div v-else class="flex items-center justify-between p-2">
|
||||||
<div class="flex-1 pr-1">{{ value.name }} <span class="text-grey-dark text-xs">({{ filesize(value.size) }})</span></div>
|
<div class="flex-1 pr-1">{{ value.name }} <span class="text-grey-dark text-xs">({{ filesize(value.size) }})</span></div>
|
||||||
<button @click="remove" type="button" class="px-4 py-1 bg-grey-dark hover:bg-grey-darker rounded-sm text-xs font-medium text-white">
|
<button type="button" class="px-4 py-1 bg-grey-dark hover:bg-grey-darker rounded-sm text-xs font-medium text-white" @click="remove">
|
||||||
Remove
|
Remove
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -22,12 +22,6 @@
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
id: {
|
|
||||||
type: String,
|
|
||||||
default() {
|
|
||||||
return `text-input-${this._uid}`
|
|
||||||
},
|
|
||||||
},
|
|
||||||
value: File,
|
value: File,
|
||||||
label: String,
|
label: String,
|
||||||
accept: String,
|
accept: String,
|
||||||
|
@ -41,7 +35,7 @@ export default {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
this.$refs.file.value = ''
|
this.$refs.file.value = ''
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
filesize(size) {
|
filesize(size) {
|
||||||
|
@ -57,6 +51,6 @@ export default {
|
||||||
remove() {
|
remove() {
|
||||||
this.$emit('input', null)
|
this.$emit('input', null)
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Reference in a new issue