diff --git a/CHANGELOG.md b/CHANGELOG.md index a700b12f..5acb0556 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed ### Removed ---> +## 0.6.1 - 2021-07-15 +### Fixed +- Users in teams + ## 0.6.0 - 2021-07-14 ### Added - Support for Jetstream/Spark teams diff --git a/LICENSE.md b/LICENSE.md index 19d5a5ce..f7cf42d3 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Venture Drake +Copyright (c) 2021 Venture Drake Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/config/package.php b/config/package.php index acec4199..5acac4b0 100644 --- a/config/package.php +++ b/config/package.php @@ -13,6 +13,6 @@ | */ - 'version' => '0.6.0', + 'version' => '0.6.1', ]; diff --git a/src/Http/Controllers/UserController.php b/src/Http/Controllers/UserController.php index fc7dbc77..5bdde880 100644 --- a/src/Http/Controllers/UserController.php +++ b/src/Http/Controllers/UserController.php @@ -3,6 +3,7 @@ namespace VentureDrake\LaravelCrm\Http\Controllers; use App\User; +use DB; use Illuminate\Support\Facades\Hash; use VentureDrake\LaravelCrm\Http\Requests\InviteUserRequest; use VentureDrake\LaravelCrm\Http\Requests\StoreUserRequest; @@ -18,14 +19,24 @@ class UserController extends Controller */ public function index() { - if (User::all()->count() < 30) { - $users = User::latest()->get(); + if (config('laravel-crm.teams')) { + if (auth()->user()->currentTeam) { + $users = auth()->user()->currentTeam->allUsers(); + + if ($users->count() > 30) { + $users = $users->paginate(30); + } + } } else { - $users = User::latest()->paginate(30); + if (User::all()->count() < 30) { + $users = User::latest()->get(); + } else { + $users = User::latest()->paginate(30); + } } return view('laravel-crm::users.index', [ - 'users' => $users, + 'users' => $users ?? [], ]); } @@ -75,7 +86,7 @@ public function store(StoreUserRequest $request) 'email' => $request->email, 'password' => Hash::make($request->password), 'crm_access' => (($request->crm_access == 'on') ? 1 : 0), - ])->save(); + ]); $roles = []; if ($request->role) { @@ -85,6 +96,20 @@ public function store(StoreUserRequest $request) } $user->syncRoles($roles); + + if (config('laravel-crm.teams')) { + if ($team = auth()->user()->currentTeam) { + DB::table('team_user')->insert([ + 'team_id' => $team->id, + 'user_id' => $user->id, + 'role' => 'editor', // Default Jetstream role + ]); + + $user->forceFill([ + 'current_team_id' => $team->id, + ])->save(); + }; + } flash(ucfirst(trans('laravel-crm::lang.user_stored')))->success()->important(); diff --git a/src/LaravelCrmServiceProvider.php b/src/LaravelCrmServiceProvider.php index 23de17e7..64c994e2 100644 --- a/src/LaravelCrmServiceProvider.php +++ b/src/LaravelCrmServiceProvider.php @@ -3,6 +3,8 @@ namespace VentureDrake\LaravelCrm; use Illuminate\Filesystem\Filesystem; +use Illuminate\Pagination\LengthAwarePaginator; +use Illuminate\Pagination\Paginator; use Illuminate\Routing\Router; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Gate; @@ -84,6 +86,25 @@ class_alias(config("auth.providers.users.model"), 'App\User'); Phone::observe(PhoneObserver::class); Email::observe(EmailObserver::class); Setting::observe(SettingObserver::class); + + // Paginate on Collection + if (! Collection::hasMacro('paginate')) { + Collection::macro( + 'paginate', + function ($perPage = 30, $page = null, $options = []) { + $page = $page ?: (Paginator::resolveCurrentPage() ?: 1); + + return (new LengthAwarePaginator( + $this->forPage($page, $perPage), + $this->count(), + $perPage, + $page, + $options + )) + ->withPath(''); + } + ); + } if ($this->app->runningInConsole()) { $this->publishes([