Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shifted from opton api to composition api #211

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
extends: ['eslint:recommended', 'plugin:vue/vue3-recommended'],
parserOptions: {
ecmaVersion: 2020,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Setup composer cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Homestead.yaml
npm-debug.log
/.idea
/.vscode
bun.lockb
4 changes: 2 additions & 2 deletions app/Http/Controllers/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function index(): Response
'contacts' => Auth::user()->account->contacts()
->with('organization')
->orderByName()
->filter(Request::only('search', 'trashed'))
->filter(Request::only(['search', 'trashed']))
->paginate(10)
->withQueryString()
->through(fn ($contact) => [
Expand Down Expand Up @@ -65,7 +65,7 @@ public function store(): RedirectResponse
])
);

return Redirect::route('contacts')->with('success', 'Contact created.');
return Redirect::route('contacts.index')->with('success', 'Contact created.');
}

public function edit(Contact $contact): Response
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/OrganizationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function index(): Response
'filters' => Request::all('search', 'trashed'),
'organizations' => Auth::user()->account->organizations()
->orderBy('name')
->filter(Request::only('search', 'trashed'))
->filter(Request::only(['search', 'trashed']))
->paginate(10)
->withQueryString()
->through(fn ($organization) => [
Expand Down Expand Up @@ -51,7 +51,7 @@ public function store(): RedirectResponse
])
);

return Redirect::route('organizations')->with('success', 'Organization created.');
return Redirect::route('organizations.index')->with('success', 'Organization created.');
}

public function edit(Organization $organization): Response
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function index(): Response
'filters' => Request::all('search', 'role', 'trashed'),
'users' => Auth::user()->account->users()
->orderByName()
->filter(Request::only('search', 'role', 'trashed'))
->filter(Request::only(['search', 'role', 'trashed']))
->get()
->transform(fn ($user) => [
'id' => $user->id,
Expand Down Expand Up @@ -59,7 +59,7 @@ public function store(): RedirectResponse
'photo_path' => Request::file('photo') ? Request::file('photo')->store('users') : null,
]);

return Redirect::route('users')->with('success', 'User created.');
return Redirect::route('users.index')->with('success', 'User created.');
}

public function edit(User $user): Response
Expand Down
12 changes: 6 additions & 6 deletions app/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Http\Middleware;

use Illuminate\Http\Middleware\TrustProxies as Middleware;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Request as RequestAlias;

class TrustProxies extends Middleware
{
Expand All @@ -20,9 +20,9 @@ class TrustProxies extends Middleware
* @var int
*/
protected $headers =
Request::HEADER_X_FORWARDED_FOR |
Request::HEADER_X_FORWARDED_HOST |
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO |
Request::HEADER_X_FORWARDED_AWS_ELB;
RequestAlias::HEADER_X_FORWARDED_FOR |
RequestAlias::HEADER_X_FORWARDED_HOST |
RequestAlias::HEADER_X_FORWARDED_PORT |
RequestAlias::HEADER_X_FORWARDED_PROTO |
RequestAlias::HEADER_X_FORWARDED_AWS_ELB;
}
35 changes: 21 additions & 14 deletions app/Models/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand All @@ -22,33 +23,39 @@ public function organization(): BelongsTo
return $this->belongsTo(Organization::class);
}

public function getNameAttribute()
public function getNameAttribute(): string
{
return $this->first_name.' '.$this->last_name;
}

public function scopeOrderByName($query)
public function scopeOrderByName($query): void
{
$query->orderBy('last_name')->orderBy('first_name');
}

public function scopeFilter($query, array $filters)
public function scopeFilter(Builder $query, array $filters): Builder
{
$query->when($filters['search'] ?? null, function ($query, $search) {
$query->where(function ($query) use ($search) {
$query->where('first_name', 'like', '%'.$search.'%')
->orWhere('last_name', 'like', '%'.$search.'%')
->orWhere('email', 'like', '%'.$search.'%')
->orWhereHas('organization', function ($query) use ($search) {
$query->where('name', 'like', '%'.$search.'%');
if (! count($filters)) {
return $query;
}

if (@$filters['search']) {
$query->where(function (Builder $query) use ($filters) {
$query->whereAny(['first_name', 'last_name', 'email'], 'like', '%'.$filters['search'].'%')
->orWhereHas('organization', function (Builder $query) use ($filters) {
$query->where('name', 'like', '%'.$filters['search'].'%');
});
});
})->when($filters['trashed'] ?? null, function ($query, $trashed) {
if ($trashed === 'with') {
}

if (@$filters['trashed']) {
if ($filters['trashed'] === 'with') {
$query->withTrashed();
} elseif ($trashed === 'only') {
} elseif ($filters['trashed'] === 'only') {
$query->onlyTrashed();
}
});
}

return $query;
}
}
21 changes: 14 additions & 7 deletions app/Models/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
Expand All @@ -22,16 +23,22 @@ public function contacts(): HasMany
return $this->hasMany(Contact::class);
}

public function scopeFilter($query, array $filters)
public function scopeFilter(Builder $query, array $filters): Builder
{
$query->when($filters['search'] ?? null, function ($query, $search) {
$query->where('name', 'like', '%'.$search.'%');
})->when($filters['trashed'] ?? null, function ($query, $trashed) {
if ($trashed === 'with') {
if (! count($filters)) {
return $query;
}
if (@$filters['search']) {
$query->where('name', 'like', '%'.$filters['search'].'%');
}
if (@$filters['trashed']) {
if ($filters['trashed'] === 'with') {
$query->withTrashed();
} elseif ($trashed === 'only') {
} elseif ($filters['trashed'] === 'only') {
$query->onlyTrashed();
}
});
}

return $query;
}
}
50 changes: 28 additions & 22 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
Expand Down Expand Up @@ -58,50 +59,55 @@ public function account(): BelongsTo
return $this->belongsTo(Account::class);
}

public function getNameAttribute()
public function getNameAttribute(): string
{
return $this->first_name.' '.$this->last_name;
}

public function setPasswordAttribute($password)
public function setPasswordAttribute($password): void
{
$this->attributes['password'] = Hash::needsRehash($password) ? Hash::make($password) : $password;
}

public function isDemoUser()
public function isDemoUser(): bool
{
return $this->email === 'johndoe@example.com';
}

public function scopeOrderByName($query)
public function scopeOrderByName($query): void
{
$query->orderBy('last_name')->orderBy('first_name');
}

public function scopeWhereRole($query, $role)
public function scopeWhereRole(Builder $query, $role): Builder
{
switch ($role) {
case 'user': return $query->where('owner', false);
case 'owner': return $query->where('owner', true);
}
return match ($role) {
'user' => $query->where('owner', false),
'owner' => $query->where('owner', true),
};
}

public function scopeFilter($query, array $filters)
public function scopeFilter(Builder $query, array $filters): Builder
{
$query->when($filters['search'] ?? null, function ($query, $search) {
$query->where(function ($query) use ($search) {
$query->where('first_name', 'like', '%'.$search.'%')
->orWhere('last_name', 'like', '%'.$search.'%')
->orWhere('email', 'like', '%'.$search.'%');
});
})->when($filters['role'] ?? null, function ($query, $role) {
$query->whereRole($role);
})->when($filters['trashed'] ?? null, function ($query, $trashed) {
if ($trashed === 'with') {
if (! count($filters)) {
return $query;
}

if (@$filters['search']) {
$query->whereAny(['first_name', 'last_name', 'email'], 'like', '%'.$filters['search'].'%');
}

if (@$filters['role']) {
$query->whereRole($filters['role']);
}
if (@$filters['trashed']) {
if ($filters['trashed'] === 'with') {
$query->withTrashed();
} elseif ($trashed === 'only') {
} elseif ($filters['trashed'] === 'only') {
$query->onlyTrashed();
}
});
}

return $query;
}
}
Loading