Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sarun Mungthanya
SpnPatch-Laravel
Commits
5e0dca88
Commit
5e0dca88
authored
Jul 16, 2024
by
Thidaporn Laisan
Browse files
update parameter
parent
27020835
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/Http/Livewire/Pages/Parameter/ParameterEdit.php
View file @
5e0dca88
...
@@ -3,15 +3,25 @@
...
@@ -3,15 +3,25 @@
namespace
App\Http\Livewire\Pages\Parameter
;
namespace
App\Http\Livewire\Pages\Parameter
;
use
Livewire\Component
;
use
Livewire\Component
;
use
Livewire\WithFileUploads
;
use
App\Models\ConfParameter
;
use
App\Models\ConfParameter
;
use
App\Models\TabParameterInfo
;
use
App\Models\TabParameterInfo
;
use
App\Models\TabSpnpage
;
use
App\Models\TabSpnpage
;
use
App\Models\TabParameterImg
;
use
App\Models\TabUser
;
use
Illuminate\Support\Facades\Storage
;
use
Illuminate\Support\Facades\Auth
;
class
ParameterEdit
extends
Component
class
ParameterEdit
extends
Component
{
{
use
WithFileUploads
;
public
$parameterId
;
public
$parameterId
;
public
$name
,
$value
,
$description
,
$active
,
$detail
,
$pageCode
=
[];
public
$name
,
$value
,
$description
,
$active
,
$detail
,
$pageCode
=
[];
public
$searchByPage
=
[];
public
$searchByPage
=
[];
public
$images
=
[];
public
$newImage
;
public
$imgdetail
,
$category
=
'1'
;
protected
$rules
=
[
protected
$rules
=
[
'name'
=>
'required|string|max:30'
,
'name'
=>
'required|string|max:30'
,
...
@@ -19,7 +29,10 @@ class ParameterEdit extends Component
...
@@ -19,7 +29,10 @@ class ParameterEdit extends Component
'description'
=>
'required|string|max:100'
,
'description'
=>
'required|string|max:100'
,
'active'
=>
'required'
,
'active'
=>
'required'
,
'detail'
=>
'required'
,
'detail'
=>
'required'
,
'pageCode'
=>
'required|array|min:1'
,
'pageCode'
=>
'required|array'
,
'newImage'
=>
'nullable|image|max:1024'
,
'imgdetail'
=>
'nullable|string|max:255'
,
'category'
=>
'nullable|string|max:100'
,
];
];
public
function
mount
(
$editPid
)
public
function
mount
(
$editPid
)
...
@@ -40,6 +53,7 @@ class ParameterEdit extends Component
...
@@ -40,6 +53,7 @@ class ParameterEdit extends Component
$this
->
pageCode
=
[];
$this
->
pageCode
=
[];
}
}
$this
->
searchByPage
=
TabSpnpage
::
select
(
'pagecode'
,
'pagename'
)
->
get
()
->
toArray
();
$this
->
searchByPage
=
TabSpnpage
::
select
(
'pagecode'
,
'pagename'
)
->
get
()
->
toArray
();
$this
->
images
=
TabParameterImg
::
where
(
'parameterCode'
,
$parameter
->
name
)
->
get
();
}
}
public
function
updateParameter
()
public
function
updateParameter
()
...
@@ -58,7 +72,7 @@ class ParameterEdit extends Component
...
@@ -58,7 +72,7 @@ class ParameterEdit extends Component
$parameterInfo
=
TabParameterInfo
::
where
(
'parameterName'
,
ConfParameter
::
where
(
'PID'
,
$this
->
parameterId
)
->
value
(
'name'
))
->
first
();
$parameterInfo
=
TabParameterInfo
::
where
(
'parameterName'
,
ConfParameter
::
where
(
'PID'
,
$this
->
parameterId
)
->
value
(
'name'
))
->
first
();
if
(
$parameterInfo
)
{
if
(
$parameterInfo
)
{
$parameterInfo
->
update
([
$parameterInfo
->
update
([
'parameterName'
=>
$this
->
name
,
// อัปเดตชื่อด้วย
'parameterName'
=>
$this
->
name
,
'pageCode'
=>
$pageCodesString
,
'pageCode'
=>
$pageCodesString
,
'detail'
=>
$this
->
detail
,
'detail'
=>
$this
->
detail
,
]);
]);
...
@@ -70,17 +84,55 @@ class ParameterEdit extends Component
...
@@ -70,17 +84,55 @@ class ParameterEdit extends Component
]);
]);
}
}
if
(
$this
->
newImage
)
{
$this
->
uploadImage
();
}
session
()
->
flash
(
'message'
,
'Parameter updated successfully!'
);
session
()
->
flash
(
'message'
,
'Parameter updated successfully!'
);
$this
->
emit
(
'loadPage'
,
'list'
);
$this
->
emit
(
'loadPage'
,
'list'
);
}
}
public
function
render
()
public
function
uploadImage
()
{
{
return
view
(
'livewire.pages.parameter.parameter-edit'
);
$this
->
validate
([
}
'newImage'
=>
'nullable|image|max:1024'
,
}
'category'
=>
'nullable|string|max:100'
,
]);
$user
=
Auth
::
user
();
if
(
!
$user
)
{
session
()
->
flash
(
'error'
,
'User not authenticated.'
);
return
;
}
if
(
$this
->
newImage
)
{
$imagePath
=
base64_encode
(
file_get_contents
(
$this
->
newImage
->
getRealPath
()));
TabParameterImg
::
create
([
'parameterCode'
=>
$this
->
name
,
'imgdetail'
=>
$imagePath
,
'category'
=>
$this
->
category
,
'uploadBy'
=>
$user
->
USERNAME
,
'uploadTime'
=>
now
(),
]);
$this
->
images
=
TabParameterImg
::
where
(
'parameterCode'
,
$this
->
name
)
->
get
();
$this
->
reset
([
'newImage'
,
'category'
]);
// Reset the input fields
$this
->
emit
(
'clearFileInput'
);
}
}
public
function
deleteImage
(
$imgid
)
{
$image
=
TabParameterImg
::
where
(
'imgid'
,
$imgid
)
->
first
();
if
(
$image
)
{
$image
->
delete
();
$this
->
images
=
TabParameterImg
::
where
(
'parameterCode'
,
$this
->
name
)
->
get
();
}
}
public
function
render
()
{
return
view
(
'livewire.pages.parameter.parameter-edit'
);
}
}
app/Models/TabParameterImg.php
View file @
5e0dca88
...
@@ -6,6 +6,9 @@ use Illuminate\Database\Eloquent\Model;
...
@@ -6,6 +6,9 @@ use Illuminate\Database\Eloquent\Model;
class
TabParameterImg
extends
Model
class
TabParameterImg
extends
Model
{
{
public
$timestamps
=
false
;
protected
$primaryKey
=
'imgid'
;
protected
$table
=
'tab_parameter_img'
;
protected
$table
=
'tab_parameter_img'
;
protected
$fillable
=
[
protected
$fillable
=
[
'imgid'
,
'imgid'
,
...
...
resources/views/livewire/pages/parameter/parameter-edit.blade.php
View file @
5e0dca88
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
class=
"btn mx-auto m-3 text-white bg-primary px-3 py-2"
>
Back
</button>
class=
"btn mx-auto m-3 text-white bg-primary px-3 py-2"
>
Back
</button>
<div
class=
"max-w-full mx-auto p-6 bg-gray-100"
>
<div
class=
"max-w-full mx-auto p-6 bg-gray-100"
>
<div
class=
"w-full px-6 mb-12 flex
justify-center
"
>
<div
class=
"w-full px-6 mb-12 flex"
>
<div
class=
"p-12 bg-white shadow-md rounded-lg w-1/2"
>
<div
class=
"p-12 bg-white shadow-md rounded-lg w-1/2"
>
<h2
class=
"text-2xl font-bold mb-4"
>
Edit Parameter
</h2>
<h2
class=
"text-2xl font-bold mb-4"
>
Edit Parameter
</h2>
...
@@ -13,6 +13,11 @@
...
@@ -13,6 +13,11 @@
{{ session('message') }}
{{ session('message') }}
</div>
</div>
@endif
@endif
@if (session()->has('error'))
<div
class=
"alert alert-danger"
>
{{ session('error') }}
</div>
@endif
<form
wire:submit.prevent=
"updateParameter"
>
<form
wire:submit.prevent=
"updateParameter"
>
<div
class=
"mb-4"
>
<div
class=
"mb-4"
>
...
@@ -75,7 +80,67 @@
...
@@ -75,7 +80,67 @@
</div>
</div>
</form>
</form>
</div>
</div>
</div>
<div
class=
"p-12 bg-white shadow-md rounded-lg w-1/2 ml-4"
>
<h2
class=
"text-2xl font-bold mb-4"
>
Upload Image
</h2>
<form
wire:submit.prevent=
"uploadImage"
>
<div
class=
"mb-4"
>
<label
for=
"newImage"
class=
"block text-sm font-medium text-gray-700"
>
Image
</label>
<input
type=
"file"
wire:model=
"newImage"
id=
"newImage"
class=
"w-full mt-1 p-2 border border-gray-300 rounded-md"
>
@error('newImage')
<span
class=
"text-red-500"
>
{{ $message }}
</span>
@enderror
</div>
<div
class=
"mb-4"
>
<label
for=
"category"
class=
"block text-sm font-medium text-gray-700"
>
Parameter
</label>
<select
wire:model.defer=
"category"
id=
"category"
class=
"mt-1 p-2 border border-gray-300 rounded-md"
>
<option
value=
"1"
>
Enable
</option>
<option
value=
"2"
>
Disable
</option>
</select>
@error('category')
<span
class=
"text-red-500"
>
{{ $message }}
</span>
@enderror
</div>
<div
class=
"flex items-center justify-center"
>
<button
type=
"submit"
class=
"bg-primary inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
>
Upload
</button>
</div>
</form>
<div
class=
"mt-6"
>
<h3
class=
"text-lg font-medium text-gray-700 mb-2"
>
Uploaded Images
</h3>
<div
class=
"flex flex-col gap-4"
>
@foreach ($images as $image)
<div
class=
"relative"
>
<img
src=
"data:image/jpeg;base64,{{ $image->imgdetail }}"
alt=
"Image"
class=
"w-full h-auto rounded-md"
>
<div
class=
"mt-2 text-sm text-gray-700"
>
<p><strong>
Parameter:
</strong>
{{ $image->category == 1 ? 'Enable' : ($image->category == 2 ? 'Disable' : '') }}
</p>
<p><strong>
Uploaded By:
</strong>
{{ $image->uploadBy }}
</p>
<p><strong>
Uploaded Time:
</strong>
{{ $image->uploadTime }}
</p>
</div>
<button
type=
"button"
wire:click=
"deleteImage({{ $image->imgid }})"
class=
"absolute top-1 right-1 bg-red-500 text-white p-1 rounded-full hover:bg-red-700"
>
<i
class=
"fa fa-trash"
></i>
</button>
</div>
@endforeach
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- JavaScript to clear file input -->
<script>
document
.
addEventListener
(
'
livewire:load
'
,
function
()
{
@
this
.
on
(
'
clearFileInput
'
,
function
()
{
let
input
=
document
.
getElementById
(
'
newImage
'
);
if
(
input
)
{
input
.
value
=
null
;
}
});
});
</script>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment