title: How should I validate a coupon in Laravel 5.1?
body: <p>I have an AJAX request coming from my checkout page that gives the user entered coupon code. This passes into my controller like so:</p>
  
  <pre><code>public function attachCoupon(AttachCouponRequest $request)
  {        
      $response = ShopHelper::checkCoupon($request-&gt;coupon);
  
      return Response::json($response);
  }
  </code></pre>
  
  <p>My 'checkCoupon' function is loaded in from a helper class and looks like so:</p>
  
  <pre><code>public static function checkCoupon($code) 
  {
      $coupon = Coupon::where('code',$code)-&gt;get();
  
      if ($coupon-&gt;isEmpty()) {
          $response = ['valid' =&gt; false, 'message' =&gt; 'Coupon code not recognised'];
      } elseif ( isset($coupon-&gt;end_date) &amp;&amp; $coupon-&gt;end_date &lt; Carbon::now()) {
          $response = ['valid' =&gt; false, 'message' =&gt; 'Sorry, that coupon has expired.'];
      } elseif ( isset($coupon-&gt;start_date) &amp;&amp; $coupon-&gt;start_date &gt; Carbon::now()) {
          $response = ['valid' =&gt; false, 'message' =&gt; 'Sorry, that coupon is not yet valid.'];
      } elseif ( isset($coupon-&gt;status) &amp;&amp; $coupon-&gt;status === 'inactive') {
          $response = ['valid' =&gt; false, 'message' =&gt; 'Sorry, that coupon is inactive.'];
      } else {
          $response = ['valid' =&gt; true, 'message' =&gt; 'Coupon applied successfully!.'];
      }
  
      return($response);
  }
  </code></pre>
  
  <p><strong>This seems very un-laravel-like, is there a neater way to do this? Can I put this into my FormRequest class 'AttachCouponRequest'? Should I be using a Service Provider?</strong></p>
  
  <p>Please help me make this more elegant.</p>
  
  <p>Thank you.</p>