Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tantricllama
Beer
Commits
243627fc
Commit
243627fc
authored
Apr 24, 2019
by
tantricllama
Browse files
added image deleting
parent
8f1e42e5
Changes
7
Hide whitespace changes
Inline
Side-by-side
app/Http/Controllers/PostsController.php
View file @
243627fc
...
...
@@ -100,18 +100,6 @@ class PostsController extends Controller
return
redirect
(
'/posts'
)
->
with
(
'success'
,
'Post Created'
);
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public
function
show
(
$id
)
{
$post
=
Post
::
find
(
$id
);
return
view
(
'posts.show'
)
->
with
(
'post'
,
$post
);
}
/**
* Show the form for editing the specified resource.
*
...
...
@@ -208,4 +196,27 @@ class PostsController extends Controller
return
redirect
(
'/posts'
)
->
with
(
'success'
,
'Post Removed'
);
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public
function
destroyImage
(
$id
)
{
$image
=
Image
::
find
(
$id
);
// Check for correct user
if
(
auth
()
->
user
()
->
id
!==
$image
->
post
->
user_id
)
{
return
0
;
}
Storage
::
delete
(
'public/posts/images/'
.
$image
->
filename
);
Storage
::
delete
(
'public/posts/thumbs/'
.
$image
->
filename
);
$image
->
delete
();
return
1
;
}
}
public/css/app.css
View file @
243627fc
...
...
@@ -10797,6 +10797,39 @@ h6 {
padding-top: 15px !important;
}
.delete-image-wrapper {
position: relative;
display: inline-block;
}
.delete-image-wrapper img {
opacity: 1;
display: block;
width: 100%;
height: auto;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.delete-image-button {
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
.delete-image-wrapper:hover img {
opacity: 0.3;
}
.delete-image-wrapper:hover .delete-image-button {
opacity: 1;
}
.navbar-laravel {
background-color: #fff;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
...
...
resources/sass/_custom.scss
View file @
243627fc
...
...
@@ -106,4 +106,36 @@ h1, h2, h3, h4, h5, h6 {
*/
.lb-dataContainer
{
padding-top
:
15px
!
important
;
}
.delete-image-wrapper
{
position
:
relative
;
display
:
inline-block
;
}
.delete-image-wrapper
img
{
opacity
:
1
;
display
:
block
;
width
:
100%
;
height
:
auto
;
backface-visibility
:
hidden
;
}
.delete-image-button
{
opacity
:
0
;
position
:
absolute
;
top
:
50%
;
left
:
50%
;
transform
:
translate
(
-50%
,
-50%
);
-ms-transform
:
translate
(
-50%
,
-50%
);
text-align
:
center
;
}
.delete-image-wrapper
:hover
img
{
opacity
:
0
.3
;
}
.delete-image-wrapper
:hover
.delete-image-button
{
opacity
:
1
;
}
\ No newline at end of file
resources/views/layouts/app.blade.php
View file @
243627fc
<!DOCTYPE html>
<html
lang=
"{{ str_replace('_', '-', app()->getLocale()) }}"
>
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script
async
src=
"https://www.googletagmanager.com/gtag/js?id=UA-138975742-1"
></script>
<script>
window
.
dataLayer
=
window
.
dataLayer
||
[];
function
gtag
(){
dataLayer
.
push
(
arguments
);}
gtag
(
'
js
'
,
new
Date
());
gtag
(
'
config
'
,
'
UA-138975742-1
'
);
</script>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
>
...
...
resources/views/posts/edit.blade.php
View file @
243627fc
...
...
@@ -12,6 +12,14 @@
{{
Form
::
label
(
'body'
,
'Body'
)}}
{{
Form
::
textarea
(
'body'
,
$post
->
body
,
[
'id'
=>
'article-ckeditor'
,
'class'
=>
'form-control'
,
'placeholder'
=>
'Body Text'
])}}
</
div
>
<
div
id
=
"image-list"
class
=
"form-group"
>
@
foreach
(
$post
->
images
as
$image
)
<
div
id
=
"image-wrapper-
{
{$image->id}
}
"
class
=
"delete-image-wrapper"
>
<
img
style
=
"height: 100px"
src
=
"/storage/posts/thumbs/
{
{$image->filename}
}
"
alt
=
"
{
{$post->title}
}
"
/>
<
button
type
=
"button"
class
=
"btn btn-danger delete-image-button"
onClick
=
"deleteImage(
{
{$image->id}
}
)"
>
Delete
</
button
>
</
div
>
@
endforeach
</
div
>
<
div
class
=
"form-group"
>
{{
Form
::
file
(
'post_image'
)}}
</
div
>
...
...
@@ -23,4 +31,22 @@
@
section
(
'scripts'
)
@
include
(
'inc.ckeditor'
)
<
script
type
=
"application/javascript"
>
function
deleteImage
(
id
)
{
if
(
confirm
(
'Are you sure you want to delete this image?'
))
{
$
.
ajax
({
url
:
'/posts/images/'
+
id
,
type
:
'POST'
,
data
:
{
_method
:
'DELETE'
,
_token
:
'{{csrf_token()}}'
},
success
:
function
(
msg
)
{
document
.
getElementById
(
'image-list'
)
.
removeChild
(
document
.
getElementById
(
'image-wrapper-'
+
id
));
}
});
}
}
</
script
>
@
endsection
\ No newline at end of file
resources/views/posts/show.blade.php
deleted
100644 → 0
View file @
8f1e42e5
@
extends
(
'layouts.app'
)
@
section
(
'content'
)
<
a
href
=
"/posts"
class
=
"btn btn-link btn-sm mb-3"
>&
laquo
;
Go
Back
</
a
>
<
h1
>
{{
$post
->
title
}}
</
h1
>
@
foreach
(
$post
->
images
as
$image
)
<
img
src
=
"/storage/posts/thumbs/
{
{$image->filename}
}
"
>
@
endforeach
<
br
>
<
br
>
<
div
>
{
!!
$post
->
body
!!
}
</
div
>
<
hr
>
<
small
>
Written
on
{{
$post
->
created_at
}}
by
{{
$post
->
user
->
name
}}
</
small
>
<
hr
>
@
auth
@
if
(
Auth
::
user
()
->
id
==
$post
->
user_id
)
<
a
href
=
"/posts/
{
{$post->id}
}
/edit"
class
=
"btn btn-secondary"
>
Edit
</
a
>
{
!!
Form
::
open
([
'action'
=>
[
'PostsController@destroy'
,
$post
->
id
],
'method'
=>
'POST'
,
'class'
=>
'd-inline-block'
])
!!
}
{{
Form
::
hidden
(
'_method'
,
'DELETE'
)}}
{{
Form
::
submit
(
'Delete'
,
[
'class'
=>
'btn btn-danger'
])}}
{
!!
Form
::
close
()
!!
}
@
endif
@
endauth
@
endsection
\ No newline at end of file
routes/web.php
View file @
243627fc
...
...
@@ -20,6 +20,7 @@ Route::get('/posts/create', 'PostsController@create');
Route
::
put
(
'/posts/{post}'
,
'PostsController@update'
);
Route
::
delete
(
'/posts/{post}'
,
'PostsController@destroy'
);
Route
::
get
(
'/posts/{post}/edit'
,
'PostsController@edit'
);
Route
::
delete
(
'/posts/images/{image}'
,
'PostsController@destroyImage'
);
// Route::resource('posts', 'PostsController');
// Auth
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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