AnumAmir1212's avatar

open a bootstrap modal using middleware

i am trying to make an eCommerce website. In it I want to add the functionality of rating different vendors. a customer's order can consist of products from different vendors. later on they are asked to rate their experience with each of the vendors. i have created a middleware in construct method which checks if the customer has rated their order. if not they are taken to the rating page. i want the middleware to trigger a modal rather than take the customer to another page.

i did some googling n found out that i need to pass a variable to the view and in the view check if the variable has some value. if yes then run a script.

BUT my issue is that i don't know which view the customer will be going to so i have no way to tell which view i should send the variable to.

since the middleware is in construct method it will get triggered for all methods/routes. eg customer tries to change their account details or view old orders etc. so no way to tell which view they maybe in.

i just want some idea on how i can trigger an overlay/modal over the users requested view so that if they don't want to do rating they can simply just close the modal and continue their work.

if its not possible then i am open to other ideas too. i just don't want my rating function to be a nuisance for the customer.

0 likes
3 replies
Snapey's avatar
Snapey
Best Answer
Level 122

Middleware is not really the place. I would do it in a view composer.

If the popup needs to appear you can set a variable in the view composer and then in your master layout see if this variable is present and include a popup blade file if so.

goatshark's avatar

@Snapey, I like the view composer idea. I was thinking, more generically, of mentioning that I use session variables as a dumping ground for that kind of thing. They're pretty baked in, and they're easy to import into a js framework of you're using one.

AnumAmir1212's avatar

@Snapey thank you for your reply. I am not aware about this "view composer" so I'll give it a read first see if it solves my problem n then close the forum. But Once again thank u for your guidance.

Please or to participate in this conversation.