Skip to content

Commit

Permalink
added upload avatar grup
Browse files Browse the repository at this point in the history
  • Loading branch information
febrihidayan committed Aug 5, 2021
1 parent 17c4af6 commit 59b60a9
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 30 deletions.
2 changes: 1 addition & 1 deletion config/laratalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
*
*/
'group' => [
'disabled' => env('LARATALK_GROUP_DISABLED', false),
'enabled' => env('LARATALK_GROUP_ENABLED', false),
'participant' => env('LARATALK_GROUP_PARTICIPANT', 300)
]
];
2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/js/app.js": "/js/app.js?id=593f8a09bccc842f5b17",
"/js/app.js": "/js/app.js?id=124cafeda7dbd8e664ea",
"/css/app.css": "/css/app.css?id=5fab102d9b0d6f4397e5"
}
13 changes: 11 additions & 2 deletions resources/js/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@
class="border-b dark:border-dark-50 ml-10"
>
<Avatar
v-model="formGroup.avatar"
:isIconGroup="true"
:isUpload="true"
:size="48"
Expand Down Expand Up @@ -916,6 +917,7 @@ export default {
content: ''
},
formGroup: {
avatar: '',
name: '',
users: []
},
Expand Down Expand Up @@ -1421,15 +1423,22 @@ export default {
sendGroup()
{
const data = new FormData()
data.append('image', this.formGroup.avatar)
data.append('name', this.formGroup.name)
this.users_add_Groups.filter(e => {
this.formGroup.users.push(e.id)
data.append('users[]', e.id)
})
axios.post('group-create', this.formGroup)
axios
.post('group-create', data)
.then(() => {
this.isBoxNewGroup = false
this.isBoxGroup = false
this.formGroup = {
avatar: '',
name: '',
users: []
}
Expand Down
25 changes: 15 additions & 10 deletions resources/js/components/modules/Avatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
>

<label
v-if="isUpload"
v-if="isUpload && (isIconGroup || !config.user_gravatar)"
@mouseover="isHover=true"
@mouseleave="isHover=false"
class="absolute rounded-full"
Expand Down Expand Up @@ -74,6 +74,7 @@ export default {
type: Boolean,
default: false
},
modelValue: [String, Object],
size: {
type: Number,
default: 10
Expand All @@ -88,11 +89,11 @@ export default {
computed: {
...mapGetters({
auth_user: 'config/profile',
storage: 'config/storage',
config: 'config/config',
}),
acceptImage() {
return 'image/' + this.storage.image_format.join(',image/')
return 'image/' + this.config.storage_image_format.join(',image/')
},
whStyle() {
Expand All @@ -115,14 +116,18 @@ export default {
const file = e.target.files[0]
this.src = URL.createObjectURL(file)
const data = new FormData()
data.append('image', file)
this.$emit('update:modelValue', file)
if (!this.isIconGroup) {
const data = new FormData()
data.append('image', file)
axios
.post('upload-avatar', data)
.then(({ data }) => {
this.auth_user.avatar = data
})
axios
.post('upload-avatar', data)
.then(({ data }) => {
this.auth_user.avatar = data
})
}
},
styleObject(size)
Expand Down
6 changes: 3 additions & 3 deletions resources/js/store/modules/config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// state
export const state = {
config: null,
languages: null,
models: null,
profile: null,
storage: null,
translations: null,
}

// getters
export const getters = {
config: state => state.config,
languages: state => state.languages,
models: state => state.models,
profile: state => state.profile,
storage: state => state.storage,
translations: state => state.translations,
}

Expand All @@ -27,10 +27,10 @@ export const actions = {
{
const config = window.laratalk

state.config = config.config
state.languages = config.languages
state.models = config.models
state.profile = config.profile
state.storage = config.storage
state.translations = config.translations
},

Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use FebriHidayan\Laratalk\Http\Controllers\Messages\StatusController;
use FebriHidayan\Laratalk\Http\Controllers\Messages\ShowController;
use FebriHidayan\Laratalk\Http\Controllers\Messages\StoreController;
use FebriHidayan\Laratalk\Http\Controllers\UploadAvatarController;
use FebriHidayan\Laratalk\Http\Controllers\Users\ChangeDarkmodeController;
use FebriHidayan\Laratalk\Http\Controllers\Users\ChangeLanguageController;
use FebriHidayan\Laratalk\Http\Controllers\Users\NewChatController;
use FebriHidayan\Laratalk\Http\Controllers\Users\UploadAvatarController;
use FebriHidayan\Laratalk\Http\Controllers\Users\UserChatController;
use Illuminate\Support\Facades\Route;

Expand Down
33 changes: 29 additions & 4 deletions src/Http/Controllers/Groups/CreateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,44 @@
use FebriHidayan\Laratalk\Models\Message;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;

class CreateController extends Controller
{
public function __invoke()
{
Validator::validate(Request::all(), [
$validate = [
'name' => 'required',
'users' => 'required:array'
]);
'users' => 'required:array',
'users.*' => 'numeric'
];

if (Request::file('image')) {

$format = implode(',', Config::storageImageFormat());
$size = Config::storageImageSize();

$validate['image'] = "required|mimes:$format|max:$size";
}

Validator::validate(Request::all(), $validate);

if (Request::file('image')) {
$path = Storage::putFile(
Config::storagePath(),
Request::file('image')
);

Request::merge([
'avatar' =>
str_replace('public', '/storage', $path)
]);

}

Request::merge([
'user_id' => Auth::id()
Expand Down Expand Up @@ -56,7 +82,6 @@ public function __invoke()
]);
}


$messageCreate = new UserListResource(
$messageCreate->select([
'*',
Expand Down
12 changes: 7 additions & 5 deletions src/Http/Controllers/LaratalkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public function __invoke()
->withScripts([
'title' => Config::name(),
'path' => Config::path(),
'config' => [
'user_gravatar' => Config::userGravatar(),
'group_enabled' => Config::groupEnabled(),
'storage_image_format' => Config::storageImageFormat(),
'storage_file_format' => Config::storageFileFormat(),
],
'profile' => [
'id' => $user->id,
'avatar' => Config::userGravatar()
Expand Down Expand Up @@ -94,11 +100,7 @@ public function __invoke()
'translations' => Laratalk::availableTranslations(
$user->{Config::userLocale()}
),
'echo' => Config::pusher(),
'storage' => [
'image_format' => Config::storageImageFormat(),
'file_format' => Config::storageFileFormat(),
]
'echo' => Config::pusher()
]);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace FebriHidayan\Laratalk\Http\Controllers;
namespace FebriHidayan\Laratalk\Http\Controllers\Users;

use FebriHidayan\Laratalk\Config;
use Illuminate\Routing\Controller;
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Resources/UserListResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function toArray($request)
$userTo = Config::userModel()::find($this->to_id);

$data += [
'avatar' => $this->group_avatar ?? Laratalk::gravatar(''),
'avatar' => $this->group_avatar ?? '',
'id' => $this->group_id,
'name' => $this->group_name,
'user_by_name' => $userBy->name,
Expand Down

0 comments on commit 59b60a9

Please sign in to comment.