AdvertiseRequest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Http\Requests;
  3. use Request;
  4. use App\Models\AdvertisesType;
  5. use Illuminate\Foundation\Http\FormRequest;
  6. class AdvertiseRequest extends FormRequest
  7. {
  8. protected $table = 'advertises';
  9. /**
  10. * Determine if the user is authorized to make this request.
  11. *
  12. * @return bool
  13. */
  14. public function authorize()
  15. {
  16. return true;
  17. }
  18. /**
  19. * Get the validation rules that apply to the request.
  20. *
  21. * @return array
  22. */
  23. public function rules()
  24. {
  25. $id = Request::route('id');
  26. $tpid = Request::route('tpid');
  27. $advType = AdvertisesType::find($tpid);
  28. if ($id) {
  29. $sort_val = 'required|unique:'.$this->table.',sort,'.$id.',id,tpid,'.$tpid;
  30. }
  31. else {
  32. $sort_val = 'required|unique:'.$this->table.',sort,null,null,tpid,'.$tpid;
  33. }
  34. if ($advType->width && $advType->height) {
  35. $image_val = 'dimensions:width='.$advType->width.',height='.$advType->height;
  36. }
  37. else {
  38. $image_val = '';
  39. }
  40. return [
  41. 'name' => 'required|max:50',
  42. 'sort' => $sort_val,
  43. 'image' => $image_val,
  44. 'href' => 'nullable|max:255',
  45. ];
  46. }
  47. }