Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Controller
- public function store(Request $request)
- {
- $request->validate([
- 'title' => 'required|max:191',
- 'account_owner_name' => 'required',
- 'bank_method1' => 'required',
- 'bank_method2' => 'required',
- 'amount' => 'required',
- 'payment_date' => 'required',
- 'image' => 'required|image|mimes:jpeg,png,jpg,giv,svg:max:2048',
- ]);
- $payment = new Payment;
- $payment->user_id = auth()->id();
- $payment->title = $request['title'];
- $payment->account_owner_name = $request['account_owner_name'];
- $payment->bank_method1 = $request['bank_method1'];
- $payment->bank_method2 = $request['bank_method2'];
- $payment->amount = $request['amount'];
- $payment->payment_date = date('Y-m-d', strtotime(str_replace('-', '/', $request['payment_date'])));
- $payment->notes = $request['notes'];
- if ($request->hasFile('image')){
- $image = $request->file('image');
- $filename = auth()->id().'-'.auth::user()->first_name.'-'.date('Y-m-d').'.'.$image->getClientOriginalExtension();
- $location = public_path('../../travelfair/uploads/payment/' . $filename);
- Image::make($image)->resize(800, 400)->save($location);
- $payment->image = $filename;
- }
- // dd($payment);
- $payment->save();
- $id = Auth::user();
- $user = User::withTrashed()->whereId(Auth::user())->first();
- $user->status_id = 3;
- dd($user);
- $user->restore();
- // dd($payment, $user);
- // return back()->withInput('payment', 'user');
- }
- // model payment
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- class Payment extends Model
- {
- protected $table = 'payment';
- protected $fillable = [
- 'user_id',
- 'title',
- 'account_owner_name',
- 'bank_method1',
- 'bank_method2',
- 'amount',
- 'image',
- 'payment_date',
- 'notes',
- 'status_id'
- ];
- protected $primaryKey = 'id';
- public function fromBank()
- {
- return $this->hasMany('App\From_bank');
- }
- public function toBank()
- {
- return $this->hasMany('App\To_bank');
- }
- public function status()
- {
- return $this->hasMany('App\Status');
- }
- public function user()
- {
- return $this->belongsTo('App\User');
- }
- }
- // model User
- <?php
- namespace App;
- use Illuminate\Notifications\Notifiable;
- use Illuminate\Foundation\Auth\User as Authenticatable;
- class User extends Authenticatable
- {
- use Notifiable;
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $fillable = [
- 'first_name', 'last_name', 'email','phone_number','category_id', 'institute', 'type_participants', 'question1', 'question2' ,'password', 'level', 'gambar', 'gender_id'
- ];
- /**
- * The attributes that should be hidden for arrays.
- *
- * @var array
- */
- protected $hidden = [
- 'password', 'remember_token',
- ];
- public function category()
- {
- return $this->belongsTo('App\Category');
- }
- public function gender()
- {
- return $this->belongsTo('App\Gender');
- }
- public function status_kehadiran()
- {
- return $this->hasMany('App\Absen');
- }
- public function payment()
- {
- return $this->hasMany('App\Payment');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement