Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. //Controller
  2. public function store(Request $request)
  3. {
  4.  
  5. $request->validate([
  6. 'title' => 'required|max:191',
  7. 'account_owner_name' => 'required',
  8. 'bank_method1' => 'required',
  9. 'bank_method2' => 'required',
  10. 'amount' => 'required',
  11. 'payment_date' => 'required',
  12. 'image' => 'required|image|mimes:jpeg,png,jpg,giv,svg:max:2048',
  13. ]);
  14. $payment = new Payment;
  15. $payment->user_id = auth()->id();
  16. $payment->title = $request['title'];
  17. $payment->account_owner_name = $request['account_owner_name'];
  18. $payment->bank_method1 = $request['bank_method1'];
  19. $payment->bank_method2 = $request['bank_method2'];
  20. $payment->amount = $request['amount'];
  21. $payment->payment_date = date('Y-m-d', strtotime(str_replace('-', '/', $request['payment_date'])));
  22. $payment->notes = $request['notes'];
  23. if ($request->hasFile('image')){
  24. $image = $request->file('image');
  25. $filename = auth()->id().'-'.auth::user()->first_name.'-'.date('Y-m-d').'.'.$image->getClientOriginalExtension();
  26. $location = public_path('../../travelfair/uploads/payment/' . $filename);
  27. Image::make($image)->resize(800, 400)->save($location);
  28.  
  29. $payment->image = $filename;
  30. }
  31. // dd($payment);
  32. $payment->save();
  33.  
  34. $id = Auth::user();
  35. $user = User::withTrashed()->whereId(Auth::user())->first();
  36. $user->status_id = 3;
  37. dd($user);
  38. $user->restore();
  39. // dd($payment, $user);
  40. // return back()->withInput('payment', 'user');
  41. }
  42.  
  43. // model payment
  44. <?php
  45.  
  46. namespace App;
  47.  
  48. use Illuminate\Database\Eloquent\Model;
  49.  
  50. class Payment extends Model
  51. {
  52. protected $table = 'payment';
  53. protected $fillable = [
  54. 'user_id',
  55. 'title',
  56. 'account_owner_name',
  57. 'bank_method1',
  58. 'bank_method2',
  59. 'amount',
  60. 'image',
  61. 'payment_date',
  62. 'notes',
  63. 'status_id'
  64. ];
  65. protected $primaryKey = 'id';
  66.  
  67. public function fromBank()
  68. {
  69. return $this->hasMany('App\From_bank');
  70. }
  71. public function toBank()
  72. {
  73. return $this->hasMany('App\To_bank');
  74. }
  75. public function status()
  76. {
  77. return $this->hasMany('App\Status');
  78. }
  79.  
  80. public function user()
  81. {
  82. return $this->belongsTo('App\User');
  83. }
  84. }
  85.  
  86. // model User
  87. <?php
  88.  
  89. namespace App;
  90.  
  91. use Illuminate\Notifications\Notifiable;
  92. use Illuminate\Foundation\Auth\User as Authenticatable;
  93.  
  94. class User extends Authenticatable
  95. {
  96. use Notifiable;
  97.  
  98. /**
  99. * The attributes that are mass assignable.
  100. *
  101. * @var array
  102. */
  103. protected $fillable = [
  104. 'first_name', 'last_name', 'email','phone_number','category_id', 'institute', 'type_participants', 'question1', 'question2' ,'password', 'level', 'gambar', 'gender_id'
  105. ];
  106.  
  107. /**
  108. * The attributes that should be hidden for arrays.
  109. *
  110. * @var array
  111. */
  112. protected $hidden = [
  113. 'password', 'remember_token',
  114. ];
  115.  
  116. public function category()
  117. {
  118. return $this->belongsTo('App\Category');
  119. }
  120. public function gender()
  121. {
  122. return $this->belongsTo('App\Gender');
  123. }
  124. public function status_kehadiran()
  125. {
  126. return $this->hasMany('App\Absen');
  127. }
  128. public function payment()
  129. {
  130. return $this->hasMany('App\Payment');
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement