-
app/Repositories/UserRepo.php
Open in GitHubuse App\User; class UserRepo { public function update($id, $data) { return User::find($id)->update($data); } // }
-
app/Http/Controllers/MyAccountController.php
Open in GitHubuse App\Repositories\UserRepo; use Illuminate\Support\Facades\Auth; class MyAccountController extends Controller { protected $user; public function __construct(UserRepo $user) { $this->user = $user; } // public function update_profile(UserUpdate $req) { $user = Auth::user(); $d = $user->username ? $req->only(['email', 'phone', 'address']) : $req->only(['email', 'phone', 'address', 'username']); if(!$user->username && !$req->username && !$req->email){ return back()->with('pop_error', __('msg.user_invalid')); } $user_type = $user->user_type; $code = $user->code; if($req->hasFile('photo')) { $photo = $req->file('photo'); $f = Qs::getFileMetaData($photo); $f['name'] = 'photo.' . $f['ext']; $f['path'] = $photo->storeAs(Qs::getUploadPath($user_type).$code, $f['name']); $d['photo'] = asset('storage/' . $f['path']); } $this->user->update($user->id, $d); return back()->with('flash_success', __('msg.update_ok')); } // }