Skip to content
Open
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ _ide_helper_models.php

tests/Vitest/auto-imports.d.ts
coverage

.hybridly
_ide_helper*
.phpstorm.meta.php
7 changes: 3 additions & 4 deletions app/Data/EditOrganizationData.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ public function __construct(
#[
DataCollectionOf(ContactData::class),
]
public readonly DataCollection $contacts,
) {
}
public readonly array $contacts,
) {}

public static function fromModel(Organization $organization): self
{
return new self(
$organization->id,
StoreOrganizationData::from($organization),
$organization->deleted_at,
ContactData::collection($organization->contacts->toArray()),
ContactData::collect($organization->contacts->toArray()),
);
}
}
6 changes: 3 additions & 3 deletions app/Data/SecurityData.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class SecurityData extends Data
{
public function __construct(public readonly ?CurrentUserData $user)
{
}
public function __construct(
public readonly ?UserData $user
) {}
}
9 changes: 4 additions & 5 deletions app/Data/StoreUserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Spatie\LaravelData\Attributes\Validation\Max;
use Spatie\LaravelData\Attributes\WithoutValidation;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Support\Validation\ValidationContext;

class StoreUserData extends Data
{
Expand All @@ -21,16 +22,14 @@ public function __construct(
public readonly RoleOption $role,
public readonly ?UploadedFile $photo_file,
#[WithoutValidation] public readonly ?int $user_id = null,
) {
}
) {}

/**
* @param array<string,mixed> $payload
* @return array<string,mixed>
*/
public static function rules(array $payload): array
public static function rules(ValidationContext $context): array
{
$user_id = Arr::get($payload, 'user_id');
$user_id = Arr::get($context->payload, 'user_id');

return [
'email' => [
Expand Down
5 changes: 2 additions & 3 deletions app/Data/UserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Carbon\Carbon;
use Spatie\LaravelData\Data;

class UserData extends Data
final class UserData extends Data
{
public function __construct(
public readonly int $id,
Expand All @@ -16,6 +16,5 @@ public function __construct(
public readonly ?string $photo_path,
public readonly ?RoleOption $role,
public readonly ?Carbon $deleted_at,
) {
}
) {}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function index(SearchData $data): HybridResponse

return hybridly('contacts.index', [
'filters' => $data,
'contacts' => ContactData::collection(
'contacts' => ContactData::collect(
$user->account
->contacts()
->with('organization')
Expand All @@ -45,7 +45,7 @@ public function create(): HybridResponse
$user = Auth::authenticate();

return hybridly('contacts.create', [
'organizations' => OrganizationData::collection(
'organizations' => OrganizationData::collect(
$user->account->organizations->toArray(),
),
]);
Expand Down Expand Up @@ -77,7 +77,7 @@ public function edit(Contact $contact): HybridResponse

return hybridly('contacts.edit', [
'contact' => EditContactData::from($contact),
'organizations' => OrganizationData::collection(
'organizations' => OrganizationData::collect(
$user->account->organizations->toArray(),
),
]);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/OrganizationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function index(SearchData $data): HybridResponse

return hybridly('organizations.index', [
'filters' => $data,
'organizations' => OrganizationData::collection(
'organizations' => OrganizationData::collect(
$user->account
->organizations()
->orderBy('name')
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function index(UserSearchData $data): HybridResponse

return hybridly('users.index', [
'filters' => $data,
'users' => UserData::collection(
'users' => UserData::collect(
$user->account
->users()
->orderByName()
Expand Down
9 changes: 5 additions & 4 deletions app/Http/Middleware/HandleHybridRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace App\Http\Middleware;

use App\Data\CurrentUserData;
use App\Data\SecurityData;
use App\Data\SharedData;
use App\Data\UserData;
use Hybridly\Http\Middleware;
use Illuminate\Support\Facades\Route;

Expand All @@ -15,9 +16,9 @@ class HandleHybridRequests extends Middleware
public function share(): SharedData
{
return SharedData::from([
'security' => [
'user' => CurrentUserData::optional(auth()->user()),
],
'security' => SecurityData::from([
'user' => UserData::optional(auth()->user()),
]),
'currentRoute' => Route::currentRouteName(),
'locale' => app()->getLocale(),
]);
Expand Down
3 changes: 3 additions & 0 deletions app/Models/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
* @mixin IdeHelperAccount
*/
class Account extends Model
{
/** @return HasMany<User> */
Expand Down
3 changes: 3 additions & 0 deletions app/Models/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
* @mixin IdeHelperContact
*/
class Contact extends Model
{
use HasFactory, SoftDeletes;
Expand Down
3 changes: 3 additions & 0 deletions app/Models/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
* @mixin IdeHelperOrganization
*/
class Organization extends Model
{
use HasFactory, SoftDeletes;
Expand Down
2 changes: 2 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

/**
* @property-read Account $account
*
* @mixin IdeHelperUser
*/
class User extends Authenticatable
{
Expand Down
45 changes: 24 additions & 21 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
"require": {
"php": "^8.1.0",
"guzzlehttp/guzzle": "^7.5",
"hybridly/laravel": "^0.1.0@alpha",
"hybridly/laravel": "^0.7.14",
"laravel/framework": "^10.0",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8",
"league/glide-laravel": "^1.0",
"spatie/laravel-data": "^2.2",
"spatie/laravel-typescript-transformer": "^2.1"
"spatie/laravel-data": "^4.11"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.13",
"barryvdh/laravel-ide-helper": "^3.1",
"fakerphp/faker": "^1.21.0",
"laravel/pint": "^1.4",
"laravel/sail": "^1.18.0",
Expand All @@ -28,7 +27,8 @@
"nunomaduro/larastan": "^2.5",
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
"spatie/laravel-ignition": "^2.0"
"spatie/laravel-ignition": "^2.0",
"spatie/laravel-typescript-transformer": "^2.5"
},
"autoload": {
"psr-4": {
Expand All @@ -42,21 +42,6 @@
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
},
"extra": {
"laravel": {
"dont-discover": []
Expand All @@ -71,5 +56,23 @@
}
},
"minimum-stability": "stable",
"prefer-stable": true
"prefer-stable": true,
"scripts": {
"test": "pest",
"lint": "php-cs-fixer fix --allow-risky=yes --dry-run",
"lint:fix": "php-cs-fixer fix --allow-risky=yes",
"post-update-cmd": "@php artisan vendor:publish --tag=laravel-assets --ansi --force",
"post-root-package-install": "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"",
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi",
"([ $COMPOSER_DEV_MODE -eq 1 ] && composer autocomplete) || true"
],
"autocomplete": [
"@php artisan ide-helper:eloquent || true",
"@php artisan ide-helper:generate || true",
"@php artisan ide-helper:meta || true",
"@php artisan ide-helper:models -M || true"
]
}
}
Loading