File tree Expand file tree Collapse file tree 9 files changed +135
-6
lines changed
app/Http/Controllers/Admin Expand file tree Collapse file tree 9 files changed +135
-6
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Http \Controllers \Admin ;
4+
5+ use App \Http \Controllers \Controller ;
6+ use App \Models \Content ;
7+ use App \Models \Post ;
8+ use App \Models \PostContent ;
9+ use Illuminate \Support \Facades \DB ;
10+ use Illuminate \Http \Request ;
11+
12+ class ContentController extends Controller
13+ {
14+ public function deleteCategoryContent (Content $ content )
15+ {
16+ $ content ->delete ();
17+ return redirect ()->back ()->withSuccess (__ ('This language data has been deleted. ' ));
18+ }
19+
20+ public function deletePostContent (PostContent $ postContent )
21+ {
22+ $ result = DB ::select ('select post_id from contents_of_posts where content_id = ? ' , [$ postContent ->id ]);
23+ if (!empty ($ result )){
24+ $ result = json_decode (json_encode ($ result ), true );
25+ $ post = Post::find ($ result [0 ]['post_id ' ]);
26+
27+ if (!empty ($ post )){
28+ if ($ post ->author_id != auth ()->user ()->id && !auth ()->user ()->hasOneOfRoles (['admin ' , 'mod ' ])){
29+ abort (403 );
30+ }
31+ }
32+ }
33+
34+ $ postContent ->delete ();
35+ return redirect ()->back ()->withSuccess ('This language data has been deleted. ' );
36+ }
37+ }
Original file line number Diff line number Diff line change @@ -4,4 +4,5 @@ bsCustomFileInput.init();
44require ( './scripts/tinymce' ) ;
55require ( './scripts/sidebar' ) ;
66require ( './scripts/proper-url' ) ;
7+ require ( './scripts/hidden-form' ) ;
78require ( './scripts/post-date' ) ;
Original file line number Diff line number Diff line change 1+ const hiddenForm = document . querySelector ( '.hidden-form' ) ;
2+ const hiddenFormInfo = document . querySelector ( '.hidden-form-info' ) ;
3+ const hiddenFormInfoButton = document . querySelector ( '.hidden-form-info button' ) ;
4+
5+ if ( hiddenForm && hiddenFormInfo && hiddenFormInfoButton ) {
6+ hiddenFormInfoButton . addEventListener ( 'click' , ( ) => {
7+ hiddenForm . classList . remove ( 'd-none' ) ;
8+ hiddenFormInfo . classList . add ( 'd-none' ) ;
9+ } ) ;
10+ }
Original file line number Diff line number Diff line change 127127 "Other posts that may interest you" : " Inne posty ktore mogą cię zainteresować" ,
128128 "Toggle navigation" : " Przełącz nawigację" ,
129129 "This url already exists." : " Taki link już istnieje." ,
130- "This value is not language." : " Ta wartość nie jest językiem."
130+ "This value is not language." : " Ta wartość nie jest językiem." ,
131+ "Delete only data for this langauge" : " Usuń dane tylko dla tego języka" ,
132+ "There is no data defined for this language." : " Nie ma zdefiniowanych danych dla tego języka." ,
133+ "Add data for this language" : " Dodaj dane dla tego języka" ,
134+ "This language data has been deleted." : " Dane tego języka zostały usuniętę."
131135}
Original file line number Diff line number Diff line change 2929 @empty ($category )
3030 <form action =" {{ route (' admin.categories.store' ) } }" method =" POST" enctype =" multipart/form-data" >
3131 @else
32- <form action =" {{ route (' admin.categories.update' , $category -> id ) } }" method =" POST" >
32+ @empty ($content )
33+ <div class =" text-center hidden-form-info" >
34+ <p >{{ __ (' There is no data defined for this language.' ) } } </p >
35+ <button type =" button" class =" btn btn-lg btn-primary fas fa-2x fa-plus" data-toggle =" tooltip" title =" {{ __ (' Add data for this language' ) } }" ></button >
36+ </div >
37+ @endempty
38+
39+ <form action =" {{ route (' admin.categories.update' , $category -> id ) } }" method =" POST" class =" {{ empty ($content ) ? ' d-none hidden-form' : ' ' } }" >
3340 @method (' PUT' )
3441 @endempty
3542 @csrf
133140 </div >
134141 <div class =" card-body" >
135142 <p class =" text-muted" >{{ __ (' Be careful when using this operation.' ) } } </p >
136- <form action =" {{ route (' admin.categories.destroy' , $category -> id ) } }" method =" POST" >
143+ <form action =" {{ route (' admin.categories.destroy' , $category -> id ) } }" method =" POST" class = " d-inline pr-2 " >
137144 @csrf
138145 @method (' DELETE ' )
139146 <button type =" submit" class =" btn btn-danger" >{{ __ (' Delete' ) } } </button >
140147 </form >
148+
149+ @if (! empty ($content ) )
150+ <form action =" {{ route (' admin.content.destroy' , $content -> id ) } }" method =" POST" class =" d-inline" >
151+ @csrf
152+ @method (' DELETE ' )
153+ <button type =" submit" class =" btn btn-danger" >{{ __ (' Delete only data for this langauge' ) } } </button >
154+ </form >
155+ @endif
141156 </div >
142157 </div >
143158 @endif
Original file line number Diff line number Diff line change 2929 @empty ($post )
3030 <form action =" {{ route (' admin.posts.store' ) } }" method =" POST" enctype =" multipart/form-data" >
3131 @else
32- <form action =" {{ route (' admin.posts.update' , $post -> id ) } }" method =" POST" >
32+ @empty ($content )
33+ <div class =" text-center hidden-form-info" >
34+ <p >{{ __ (' There is no data defined for this language.' ) } } </p >
35+ <button type =" button" class =" btn btn-lg btn-primary fas fa-2x fa-plus" data-toggle =" tooltip" title =" {{ __ (' Add data for this language' ) } }" ></button >
36+ </div >
37+ @endempty
38+
39+ <form action =" {{ route (' admin.posts.update' , $post -> id ) } }" method =" POST" class =" {{ empty ($content ) ? ' d-none hidden-form' : ' ' } }" >
3340 @method (' PUT' )
3441 @endempty
3542 @csrf
183190 </div >
184191 <div class =" card-body" >
185192 <p class =" text-muted" >{{ __ (' Be careful when using this operation.' ) } } </p >
186- <form action =" {{ route (' admin.posts.destroy' , $post -> id ) } }" method =" POST" >
193+ <form action =" {{ route (' admin.posts.destroy' , $post -> id ) } }" method =" POST" class = " d-inline pr-2 " >
187194 @csrf
188195 @method (' DELETE ' )
189196 <button type =" submit" class =" btn btn-danger" >{{ __ (' Delete' ) } } </button >
190197 </form >
198+
199+ @if (! empty ($content ) )
200+ <form action =" {{ route (' admin.post-content.destroy' , $content -> id ) } }" method =" POST" class =" d-inline" >
201+ @csrf
202+ @method (' DELETE ' )
203+ <button type =" submit" class =" btn btn-danger" >{{ __ (' Delete only data for this langauge' ) } } </button >
204+ </form >
205+ @endif
191206 </div >
192207 </div >
193208 @endif
Original file line number Diff line number Diff line change 2929 Route::delete ('/posts/{post}/image ' , 'PostsController@destroyImage ' )->name ('posts.image.destroy ' );
3030 Route::resource ('posts ' , 'PostsController ' )->except ('show ' );
3131
32+ Route::delete ('/post-content/{postContent} ' , 'ContentController@deletePostContent ' )->name ('post-content.destroy ' );
33+
3234 Route::middleware ('role:admin ' )->group (function (){
35+ Route::delete ('/content/{content} ' , 'ContentController@deleteCategoryContent ' )->name ('content.destroy ' );
36+
3337 Route::put ('/users/{user}/image ' , 'UsersController@updateImage ' )->name ('users.image.update ' );
3438 Route::delete ('/users/{user}/image ' , 'UsersController@destroyImage ' )->name ('users.image.destroy ' );
3539 Route::put ('/users/{user}/password ' , 'UsersPasswordController ' )->name ('users.password ' );
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tests \Feature \Admin ;
4+
5+ use App \Models \PostContent ;
6+ use App \Models \Content ;
7+ use Tests \TestCase ;
8+
9+ class ContentTest extends TestCase
10+ {
11+ private $ admin ;
12+
13+ public function setUp (): void
14+ {
15+ parent ::setUp ();
16+
17+ $ this ->admin = $ this ->getAdmin ();
18+ }
19+
20+ public function testDestroyCategoryContent ()
21+ {
22+ $ content = Content::all ()->random ();
23+ $ response = $ this ->actingAs ($ this ->admin )->delete (route ('admin.content.destroy ' , $ content ->id ));
24+
25+ $ response ->assertSessionHas ('success ' );
26+ $ response ->assertStatus (302 );
27+
28+ $ emptyContent = Content::find ($ content ->id );
29+ $ this ->assertEmpty ($ emptyContent );
30+ }
31+
32+ public function testDestroyPostContent ()
33+ {
34+ $ content = PostContent::all ()->random ();
35+ $ response = $ this ->actingAs ($ this ->admin )->delete (route ('admin.post-content.destroy ' , $ content ->id ));
36+
37+ $ response ->assertSessionHas ('success ' );
38+ $ response ->assertStatus (302 );
39+
40+ $ emptyContent = PostContent::find ($ content ->id );
41+ $ this ->assertEmpty ($ emptyContent );
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments