|
| 1 | +<?php |
| 2 | +namespace App\Classes; |
| 3 | + |
| 4 | +use App\User; |
| 5 | +use App\Provider; |
| 6 | +use App\Models\Client; |
| 7 | +use Illuminate\Support\Facades\Hash; |
| 8 | +use Illuminate\Support\Str; |
| 9 | + |
| 10 | +class UserControlClass { |
| 11 | + public function saveUser($data,$usertype) |
| 12 | + { |
| 13 | + $user = User::where('email', $data['email'])->where('isdelete', false)->get(); |
| 14 | + if(count($user)) |
| 15 | + { |
| 16 | + $user[0]->email = $data['email']; |
| 17 | + $user[0]->name = $data['name']; |
| 18 | + $user[0]->phone = $data['phone']; |
| 19 | + if(isset($data['new_password']) && $data['new_password'] != "") |
| 20 | + $user[0]->password = Hash::make($data['new_password']); |
| 21 | + $user[0]->update(); |
| 22 | + $user[0]->assignRole($usertype); |
| 23 | + return $user[0]; |
| 24 | + } |
| 25 | + $data['isdelete'] = false; |
| 26 | + $newUser = User::create([ |
| 27 | + 'name' => $data['name'], |
| 28 | + 'email' => $data['email'], |
| 29 | + 'phone' => $data['phone'], |
| 30 | + 'isdelete' => $data['isdelete'], |
| 31 | + 'password' => Hash::make($data['new_password']), |
| 32 | + ]); |
| 33 | + $newUser->assignRole($usertype); |
| 34 | + return $newUser; |
| 35 | + } |
| 36 | + |
| 37 | + public function updateUser($id, $data, $usertype) |
| 38 | + { |
| 39 | + $users = User::find($id); |
| 40 | + $users->email = $data['email']; |
| 41 | + $users->name = $data['name']; |
| 42 | + $users->phone = $data['phone']; |
| 43 | + if(isset($data['new_password']) && $data['new_password'] != "") |
| 44 | + $users->password = Hash::make($data['new_password']); |
| 45 | + $users->update(); |
| 46 | + $users->assignRole($usertype); |
| 47 | + return $users; |
| 48 | + } |
| 49 | + |
| 50 | + public function saveProvider($data) |
| 51 | + { |
| 52 | + $user = self::saveUser($data, "Provider"); |
| 53 | + Provider::create([ |
| 54 | + 'companyname' => $data['companyname'], |
| 55 | + 'addline1' => $data['addline1'], |
| 56 | + 'country' => $data['country'], |
| 57 | + 'cp' => $data['cp'], |
| 58 | + 'user_id' => $user->id, |
| 59 | + ]); |
| 60 | + } |
| 61 | + |
| 62 | + public function saveClient($data) |
| 63 | + { |
| 64 | + $user = self::saveUser($data, "Client"); |
| 65 | + Client::create([ |
| 66 | + 'companyname' => $data['companyname'], |
| 67 | + 'addline1' => $data['addline1'], |
| 68 | + 'country' => $data['country'], |
| 69 | + 'cp' => $data['cp'], |
| 70 | + 'numberofemployees' => $data['numberofemployees'], |
| 71 | + 'service' => $data['service'], |
| 72 | + 'payment' => $data['payment'], |
| 73 | + 'user_id' => $user->id, |
| 74 | + ]); |
| 75 | + } |
| 76 | + |
| 77 | + public function editProvider($id, $data) |
| 78 | + { |
| 79 | + $providers = Provider::find($id); |
| 80 | + $user = self::updateUser($providers->user_id, $data, "Provider"); |
| 81 | + $providers->companyname = $data['companyname']; |
| 82 | + $providers->addline1 = $data['addline1']; |
| 83 | + $providers->country = $data['country']; |
| 84 | + $providers->cp = $data['cp']; |
| 85 | + $providers->user_id = $user->id; |
| 86 | + $providers->update(); |
| 87 | + } |
| 88 | + |
| 89 | + public function editClient($id, $data) |
| 90 | + { |
| 91 | + $clients = Client::find($id); |
| 92 | + $user = self::updateUser($clients->user_id, $data, "Client"); |
| 93 | + $clients->companyname = $data['companyname']; |
| 94 | + $clients->addline1 = $data['addline1']; |
| 95 | + $clients->country = $data['country']; |
| 96 | + $clients->cp = $data['cp']; |
| 97 | + $clients->numberofemployees = $data['numberofemployees']; |
| 98 | + $clients->service = $data['service']; |
| 99 | + $clients->payment = $data['payment']; |
| 100 | + $clients->user_id = $user->id; |
| 101 | + $clients->update(); |
| 102 | + } |
| 103 | +} |
0 commit comments