Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdrake committed Jul 15, 2021
2 parents 6ec5239 + d4876e9 commit 6a98f31
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/package.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
|
*/

'version' => '0.6.0',
'version' => '0.6.1',

];
35 changes: 30 additions & 5 deletions src/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ?? [],
]);
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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();

Expand Down
21 changes: 21 additions & 0 deletions src/LaravelCrmServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit 6a98f31

Please # to comment.