File tree Expand file tree Collapse file tree 4 files changed +46
-6
lines changed Expand file tree Collapse file tree 4 files changed +46
-6
lines changed Original file line number Diff line number Diff line change 33namespace App \Http \Controllers ;
44
55use App \Models \User ;
6+ use App \Services \Operations ;
67use Illuminate \Http \Request ;
8+ use Illuminate \Contracts \Encryption \DecryptException ;
9+ use Illuminate \Support \Facades \Crypt ;
710
811class MainController extends Controller
912{
@@ -25,4 +28,15 @@ public function newNote()
2528 echo "I'm creating a new note! " ;
2629 }
2730
31+ public function editNote ($ id )
32+ {
33+ $ id = Operations::decryptId ($ id );
34+ echo "I'm editing note with id = {$ id }" ;
35+ }
36+
37+ public function deleteNote ($ id )
38+ {
39+ $ id = Operations::decryptId ($ id );
40+ echo "I'm deleting note with id = {$ id }" ;
41+ }
2842}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Services ;
4+
5+ use Illuminate \Contracts \Encryption \DecryptException ;
6+ use Illuminate \Support \Facades \Crypt ;
7+
8+ class Operations
9+ {
10+
11+ public static function decryptId ($ value )
12+ {
13+ try {
14+ $ value = Crypt::decrypt ($ value );
15+ } catch (DecryptException $ e ) {
16+ return redirect ()->route ('home ' );
17+ }
18+
19+ return $ value ;
20+ }
21+ }
Original file line number Diff line number Diff line change 44 <div class =" row" >
55 <div class =" col" >
66 <h4 class =" text-info" >{{ $note [' title' ] } } </h4 >
7- <small class =" text-secondary" ><span class =" opacity-75 me-2" >Created at:</span ><strong >{{ $note [' created_at' ] } } </strong ></small >
7+ <small class =" text-secondary" ><span class =" opacity-75 me-2" >Created at:</span ><strong >{{ date ( ' Y-m-d H:i:s ' , strtotime ( $note [' created_at' ])) } } </strong ></small >
88 </div >
99 <div class =" col text-end" >
10- <a href =" # " class =" btn btn-outline-secondary btn-sm mx-1" ><i class =" fa-regular fa-pen-to-square" ></i ></a >
11- <a href =" # " class =" btn btn-outline-danger btn-sm mx-1" ><i class =" fa-regular fa-trash-can" ></i ></a >
10+ <a href =" {{ route ( ' edit ' , [ ' id ' => Crypt :: encrypt ( $note [ ' id ' ]) ]) } } " class =" btn btn-outline-secondary btn-sm mx-1" ><i class =" fa-regular fa-pen-to-square" ></i ></a >
11+ <a href =" {{ route ( ' delete ' , [ ' id ' => Crypt :: encrypt ( $note [ ' id ' ]) ]) } } " class =" btn btn-outline-danger btn-sm mx-1" ><i class =" fa-regular fa-trash-can" ></i ></a >
1212 </div >
1313 </div >
1414 <hr >
Original file line number Diff line number Diff line change 1212});
1313
1414Route::middleware ([CheckIsLogged::class]) ->group (function (){
15- Route::get ('/ ' , [ MainController::class, 'index ' ])->name ('home ' );
16- Route::get ('newNote ' , [ MainController::class, 'newNote ' ])->name ('new ' );
17- Route::get ('logout ' , [ AuthController::class, 'logout ' ])->name ('logout ' );
15+ Route::get ('/ ' , [ MainController::class, 'index ' ])->name ('home ' );
16+ Route::get ('/newNote ' , [ MainController::class, 'newNote ' ])->name ('new ' );
17+
18+
19+ Route::get ('/editNote/{id} ' , [ MainController::class, 'editNote ' ])->name ('edit ' );
20+ Route::get ('/deleteNote/{id} ' , [ MainController::class, 'deleteNote ' ])->name ('delete ' );
21+
22+ Route::get ('/logout ' , [ AuthController::class, 'logout ' ])->name ('logout ' );
1823});
You can’t perform that action at this time.
0 commit comments