Alternate option for call a function in all controller in spring - spring

I have a notification section in my user area in my project. For the users there is lot of pages actually and each page i need to show the notification on top but each page calling different controller function. So my question is there any option for me to get this notification list on each user pages without calling the same notification fetching function on all controller or on all request mapping function.

Related

Save data through the controller after an event has been fired in laravel

I'm allowing a user to upload a post which includes an image and some related information as well as select the promotion fee[bronze,silver or gold].In my /post controller i'm validating the request and then sending a request to another API[third party api for performing payments].The API takes the user phone number and the promotion fee selected and does the payment transaction.So i made the Transaction model[used to save details concerning the completed transaction]to dispatch a created event since i want to save the other post related information only if the payment is successful.
I've tried to create the listener for the TransactionCreatedEvent but i can't find a way to pass the post related data into the listener in order to save them. I also tried to use the closure by calling the listen method on the Event Facade inside the post controller to no avail.
Mh, i'm not quite sure if i undestood you question correctly, but in you case, you could either relate the Transaction with the post, or pass the Transaction and the Post Model to any event or to a job, and then do whatever you want with the data in the event handler or job

How to minimize axios posts with controller actions

I am creating an application with Laravel and VueJs. In this application a user can create an event. These events have participants. In my application the user fills out all of the event information and participants information and then clicks submit.
What I am looking for guidance on is how to best structure this in the backend. What I need to accomplish is the following:
create an event to the database
create participants
do an action based on the participants in the event (would happen in the event controller)
right now the way I have structured this is:
Send an axios post to create the event (EventController)
then send an axios post to create participants (ParticipantController)
then send another axios post to the event controller to do the last action (EventController)
this to me feels like way too many axios post calls, but I don't want to just put everything in one controller. Is there a better way to do what I am wanting to do while minimizing the number of axios calls?
if you need to create participants and perform particular action after event create then you can use laravel observers you can use it's created function to perform any action like after createing an event you have to make some enteries on participant table so you can perform those actions in that observer function.

Email notification whenever a comment is created via WP REST API

I'm building a custom comment form for my Vue.js & WordPress Single Page Application theme and was able to post a comment via ajax POST request to the WP REST API. But I don't get any admin notifications on a new comment even the settings in Settings-->Reading are set to notify the admin each time a comment is created/added.
So how can I get email notifications on WP REST API comment creation?
For any reason the WP REST API team didn't use the function wp_new_comment whenever a comment is added/created. This function includes the comment_post action hook which, in turn, is used by WordPress to send admin notifications in wp-includes/default-filters.php.
Instead they've used the wp_insert_comment() function which is defined in wp-includes/comments.php and which also includes an action hook of the same name wp_insert_comment at the very end of the function. This hook we can use to trigger the notification function wp_new_comment_notify_moderator(). Just add the following snippet into your theme's / plugin's functions.php
add_action( 'wp_insert_comment', 'wp_new_comment_notify_moderator' );
see also:
https://core.trac.wordpress.org/ticket/40352
https://wordpress.org/support/topic/wp-api-comments-not-sending-notifications/#post-8987973

How to handle Stripe payment failure via AJAX, with standard page load for success? (using Laravel backend)

I've got a long and fairly complex form for a booking system that a user fills in, then pays using Stripe Checkout. I'm trying to figure out the best solution to both handle payment failure easily (so submitting form over AJAX so I don't have to try and regenerate the whole booking form with all the data the user's entered), whilst also handling payment success gracefully (so with a new page showing a booking summary and a different URL so if user clicks reload button in their browser it doesn't just take them back to the search results and booking form again)
I'm using a mixture of Laravel 5.4 and JS/JQuery to generate the booking form on the front end, and after Stripe Checkout (I'm using their standard simple integration pop up) it submits all the form + Stripe token etc back to a POST route in my Laravel backend. In my controller, I then try and charge the credit card using standard Stripe API and process the booking details into my database, and then return a Laravel view from a Blade template thus giving the user a different page and URL. As mentioned I want to switch the form submission to AJAX so payment failure can be handled easily (i.e. their big filled in form doesn't disappear, and just an alert pops up to user so they can try and enter a new card into the Stripe Checkout). That bit's fine, I'll just use this: https://stackoverflow.com/a/34099169/4059141 but then in payment succeeds I basically want the same behaviour as if I'd done a regular form POST, so the new page being displayed with a new URL.
I can generate and pass back the rendered HTML from the blade template over AJAX no problem, but that leaves the original URL in the browser's address bar, so if they hit reload on the booking summary they'll just see the search results page and blank booking form again - not what I want.
Any thoughts on a solution are welcome! Thanks

How the view communicate with controller in MVC?

I am trying to understand and use the MVC without a framework, until now I clearly understand what is the role of Model, View and Controller and how are they made.
But I have one question. If the Controller is a class with methods for every action in thew View, and in that method we communicate with the Model and ask some data or send some data, and then send that data to the view that we choose to display. My question is how we call that method from view when we need to send some data from view to controller?
Let say that we have a page with all users and when we click one user we want information about him and we send his id with post or get and we have a UserController with a GetUserInformation method wich communicate with model send the id receive the information set it to the view and call view() to show the information.
How do we call this method from View when the client clicks that user?
We made another file between them and send the user to that file and in that file we instantiate a controller object and call the method? But if we do that how is that file called in MVC?
And there are a lot of example, like login, add a user and so on when we need to call a method from controller and send some data or just call it without send data.
The general idea is how we call a method from a Controller object on an action in html page?
Since you have multiple php posts, I will assume that you are referring to implementing MVC or MVC-inspired architecture in context of web applications.
First of all: controllers are not responsible for passing data from the model layer (not a "model class") to the current view. The controller in MVC is only responsible for altering the state of the model layer (and in extremely rare cases - the current view's state) based on the user's input.
The second thing that you have to understand is the request-response nature of php. The instances in your application do not live past the execution of the site's code.
As for the view, its task is to create a response, which gets sent to a user. The "user" for your web application is not a human. Instead, what actually gets the response is a browser. And the browser does not get "the view". It only receives the response that was produced by the view.
Therefore:
It is not possible, in correctly implemented MVC-based web applications, for a view to call methods on the controller because:
you are not interacting with a view, but with a response
the view and controller are both already destroyed
P.S: at the beginning you wrote "until now I clearly understand what is the role of model,view and controller and how are they made", but it is clearly untrue.

Resources