Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. Schema::create('services', function(Blueprint $table)
  2. {
  3. $table->increments('id');
  4. $table->binary('image');
  5. $table->timestamps();
  6. });
  7.  
  8. Schema::create('services_products', function(Blueprint $table)
  9. {
  10. $table->increments('id');
  11. $table->integer('service_id')->unsigned();
  12. $table->binary('image');
  13. $table->binary('pdf');
  14.  
  15. $table->foreign('service_id')->references('id')->on('services')->onDelete('cascade');
  16. $table->timestamps();
  17. });
  18.  
  19. Schema::create('services_product_translations', function(Blueprint $table)
  20. {
  21. $table->increments('id');
  22. $table->integer('product_id')->unsigned();
  23. $table->string('title', 150);
  24. $table->longText('details');
  25. $table->string('locale')->index();
  26.  
  27. $table->unique(['product_id', 'locale']);
  28. $table->foreign('product_id')->references('id')->on('services_products')->onDelete('cascade');
  29. });
  30.  
  31. class Service extends Eloquent
  32. {
  33.  
  34. use DimsavTranslatableTranslatable;
  35.  
  36. public $translatedAttributes = ['title', 'brief'];
  37. public $translationModel = 'ServicesTranslation';
  38.  
  39. public function servicesPro()
  40. {
  41. return $this->hasMany('ServicesProduct', 'service_id');
  42. }
  43. }
  44.  
  45. class ServicesProduct extends Eloquent
  46. {
  47. use DimsavTranslatableTranslatable;
  48.  
  49. public $translatedAttributes = ['title', 'details'];
  50. public $translationModel = 'ServicesProductTranslation';
  51.  
  52.  
  53. public function services()
  54. {
  55. return $this->belongsTo('Service', 'service_id');
  56. }
  57.  
  58. public function proImage()
  59. {
  60. return $this->hasMany('ServicesProductImage', 'image_id');
  61. }
  62.  
  63. public function proVideo()
  64. {
  65. return $this->hasMany('ServicesProductVideo', 'video_id');
  66. }
  67.  
  68. public function store()
  69. {
  70. $sev_id = Input::get('category');
  71. $file = Input::file('image');
  72. $pdf = Input::file('pdf');
  73.  
  74. $destination_path = 'images/servicesProductsImages/';
  75. $filename = str_random(6) . '_' . $file->getClientOriginalName();
  76. $file->move($destination_path, $filename);
  77.  
  78. $destination_path_pdf = 'images/servicesProductsPdf/';
  79. $filenamePdf = str_random(6) . '_' . $pdf->getClientOriginalName();
  80. $pdf->move($destination_path_pdf, $filenamePdf);
  81.  
  82.  
  83. $newSerPro = new ServicesProduct();
  84.  
  85. $newSerPro->service_id = $sev_id;
  86. $newSerPro->image = $filename;
  87. $newSerPro->pdf = $filenamePdf;
  88. $newSerPro->save();
  89.  
  90. $localization = Input::get('localization');
  91. $locales = array_keys($localization);
  92. foreach ($locales as $locale) {
  93. if (!in_array($locale, array('en', 'ar'))) {
  94. Session::flash('message', 'Lang Error');
  95. return Redirect::to('admin/create-service-sub-category');
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement