php – Laravel web middleware on API routes

I use Laravel 5.8 and design an API. I was wondering if there was a setback in using a network Middleware in the API context?

I've created a new API route middleware that uses sessions, but I see an error Canister is not set on request. which is solved by using network Middleware.

Why not want to use methods from network Middleware in the API context?

PHP – Symfony 4 controller with multiple forms

I have several pages in my app that have multiple forms. In this example, the Account page has two forms: 1) Allow the user to change their password, and 2) Allow the user to contact support. I am new to Symfony and would like to get an understanding of whether I follow the best practices in this situation.

entityManager = $ entityManager;
$ this-> passwordEncoder = $ passwordEncoder;
$ this-> mailer = $ mailer;
}

/ **
* @Route ("/ ui / account", name = "account")
* /
Public functions account (Request $ request): Answer
{
$ user = $ this-> getUser ();

$ changePasswordForm = $ this-> createForm (ChangePasswordFormType :: class);
$ contactSupportForm = $ this-> createForm (ContactSupportFormType :: class);

$ changePasswordForm-> handleRequest ($ request);
$ contactSupportForm-> handleRequest ($ request);

if ($ changePasswordForm-> isSubmitted () && $ changePasswordForm-> isValid ()) {

$ plainPassword = $ changePasswordForm-> get (& # 39; password & # 39;) -> getData ();
$ this-> updatePassword ($ user, $ plainPassword);
}

if ($ contactSupportForm-> isSubmitted () && $ contactSupportForm-> isValid ()) {

$ subject = $ contactSupportForm-> get (& # 39; subject & # 39;) -> getData ();
$ message = $ contactSupportForm-> get (& # 39; message & # 39;) -> getData ();
$ this-> contactSupport ($ user, $ subject, $ message);
}

return $ this-> render (& # 39; u / account.html.twig & # 39; [
            'changePasswordForm' => $changePasswordForm->createView(),
            'contactSupportForm' => $contactSupportForm->createView(),
        ]);
}

private function updatePassword ($ user, $ plainPassword)
{
$ user-> setPassword ($ this-> passwordEncoder-> encodePassword ($ user, $ plainPassword));
$ this-> entityManager-> persist ($ user);
$ this-> entityManager-> flush ();
$ this-> addFlash (& # 39; success & # 39 ;, & # 39; your password has been updated successfully! & # 39;);
}

private function contactSupport ($ user, $ subject, $ message)
{
$ email = (new  Swift_Message (& # 39; Support Request for Registered Users & # 39;))
-> setFrom (& # 39; app@mydomain.com & # 39;
-> setTo (& # 39; support@mydomain.com & # 39;)
-> setBody (
$ this-> renderView (
& # 39; emails / support.html.twig & # 39 ;, [
                    'user' => $user, 
                    'subject' => $subject, 
                    'message' => $message, 
                ]
            )
& # 39; text / html & # 39;
);

$ this-> mailer-> send ($ email);
$ this-> addFlash ('success', & # 39; your message has been successfully sent! & # 39;);
}

}

Some specific concerns I have:

  • Is this the correct use of the constructor? For example, I often do
    The EntityManager is declared directly in controller methods declared in
    Documentation examples. Should I declare them in the specified VARs?
    Constructor as a private property of the class?
  • Is it a good practice to have multiple forms handled by one user?
    Single controller in this way? If not, what is a fresh start
    Alternative?

Since I was formally in a development team, I miss critical peer reviews a lot and I would be very happy about findings and / or recommendations.

PHP – Add custom checkout information to the confirmation page, emails, and order details

I'm trying to implement an offer where the user gets a free T-shirt when they place their first order.

I have managed to have the information displayed perfectly on the checkout page when the result is that it is the first order. However, this information will not appear on the confirmation page (thank you page), in the customer order info e-mails or in the order details of when I need to process the order.

All help grateful. I have so far:

// -----------------------------------------
// ADD FIRST ORDER T-SHIRT

add_action (& # 39; woocommerce_review_order_after_cart_contents & # 39 ;, & # 39; checkout_review_order_custom_field & # 39;);

Function has_bought ($ user_id = 0) {
global $ wpdb;
$ customer_id = $ user_id == 0? get_current_user_id (): $ user_id;
$ paid_order_statuses = array_map (& # 39; esc_sql & # 39; wc_get_is_paid_statuses ());

$ results = $ wpdb-> get_col ("
SELECT p.ID FROM {$ wpdb-> prefix} posts AS p
INNER JOIN {$ wpdb-> prefix} postmeta AS pm ON p.ID = pm.post_id
WHERE p.post_status IN (& # 39; wc- ". Implode (" & # 39 ;, & # 39; wc- ", $ paid_order_statuses)." & # 39;)
AND p.post_type LIKE # shop_order & # 39;
AND pm.meta_key = & # 39; _customer_user & # 39;
AND pm.meta_value = $ customer_id
");

// Count the number of orders and return a Boolean value, depending on whether it is greater than 0
Return number ($ results)> 0? true wrong;
}

Function checkout_review_order_custom_field () {
if (has_bought ())
echo & # 39; & # 39 ;;
otherwise
echo & # 39;T-shirt × 1Free (1st order)& # 39 ;;
}

php – coupon code is not set, no error

I've created a system for automatically creating coupon codes based on specific criteria for a user. The code generation works fine and I can test this by passing the coupon code through the URL (as follows? Code = 34o77134iy3). By copying and pasting this code and then pressing Apply Discount (34o77134iy3 in this case), the code will be applied correctly, but the following code will not be applied automatically.

$ coupon = "34o77134iy3";

Mage :: getSingleton (? Checkout / cart?) -> getQuote () -> getShippingAddress () -> setCollectShippingRates (true);
Mage :: getSingleton (# 39; checkout / cart #) -> getQuote () -> setCouponCode ($ coupon) -> collectTotals () -> save ();
Mage :: getSingleton ("checkout / session") -> setCartCouponCode ($ coupon);

Convert data to chart with PHP MySQL

I have a table called cell_daily in my database where the records are
Here

I want to use PHP to convert this data to a diagram, just like in this diagram example

I'm stuck when I use date Column as xAxis is always looped. Can you help me to solve this problem and which diagram should I use?
For your information: The table must always be updated by the user.

php – Embed a link to delete an entry in an automated email

I'm creating a job board (using WP Job Manager) that users do not need to register to post a job. However, I would like them to be able to delete (and at least delete) their entry. The solution would be to include in an email a set of URLs that would allow them to do so.

I've found suggestions like these: trigger WordPress actions from email ?, but I'm pretty new to WordPress and totally new to PHP, and I do not understand where / how I should implement these things at all.

I do not need a special email that fires after a set time. It would be ideal to embed the link to delete / edit in the original e-mail with the thank you. I use Woocommerce and thought I could embed this in the email template, but no idea where to start!

Any advice on how to do this would be very grateful!