0
\$\begingroup\$

I have friendship functionality in my Laravel application and saw Crypt is available from within blade view templates. Is this a common practice when trying to send data with your Livewire action method that you don't want the user manipulating in the browser?

public function acceptFriendRequest($senderId)
 {
 try {
 $requester_id = Crypt::decrypt($senderId);
 $requester = User::find($requester_id);
 $user = Auth::user();
 $user->acceptFriendRequest($requester);
 $this->render();
 
 } catch (DecryptException $e) {
 session()->flash('error', 'Invalid user ID.');
 }
 }

Blade view code:

<div class="friend-request">
 <p>{{ $req->sender->name }} has sent you a connection request.</p>
 <button wire:click="acceptFriendRequest('{{ Crypt::encrypt($req->sender->id) }}')" class="btn btn-success">Accept</button>
 <button wire:click="rejectFriendRequest('{{ Crypt::encrypt($req->sender->id) }}')" class="btn btn-danger">Reject</button>
 </div>
Sᴀᴍ Onᴇᴌᴀ
29.5k16 gold badges45 silver badges201 bronze badges
asked Sep 7, 2024 at 0:56
\$\endgroup\$

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.