-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Repository related supports now a custom casts. (#302)
* Repository related supports now a custom casts. * Apply fixes from StyleCI (#303) * docs
- Loading branch information
Showing
12 changed files
with
198 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Binaryk\LaravelRestify\Repositories\Casts; | ||
|
||
use Binaryk\LaravelRestify\Contracts\RestifySearchable; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\Relations\Relation; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Collection; | ||
|
||
class RelatedCast extends RepositoryCast | ||
{ | ||
public static function fromBuilder(Request $request, Builder $builder): Collection | ||
{ | ||
return $builder->take($request->input('relatablePerPage') ?? (static::$defaultRelatablePerPage ?? RestifySearchable::DEFAULT_RELATABLE_PER_PAGE))->get(); | ||
} | ||
|
||
public static function fromRelation(Request $request, Relation $relation): Collection | ||
{ | ||
return $relation->take($request->input('relatablePerPage') ?? (static::$defaultRelatablePerPage ?? RestifySearchable::DEFAULT_RELATABLE_PER_PAGE))->get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Binaryk\LaravelRestify\Repositories\Casts; | ||
|
||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\Relations\Relation; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Collection; | ||
|
||
abstract class RepositoryCast | ||
{ | ||
abstract public static function fromBuilder(Request $request, Builder $builder): Collection; | ||
|
||
abstract public static function fromRelation(Request $request, Relation $relation): Collection; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,9 @@ | |
|
||
namespace Binaryk\LaravelRestify\Tests\Feature\Authentication; | ||
|
||
use Binaryk\LaravelRestify\Contracts\Passportable; | ||
use Binaryk\LaravelRestify\Exceptions\AuthenticatableUserException; | ||
use Binaryk\LaravelRestify\Exceptions\Eloquent\EntityNotFoundException; | ||
use Binaryk\LaravelRestify\Models\LaravelRestifyModel; | ||
use Binaryk\LaravelRestify\Services\AuthService; | ||
use Binaryk\LaravelRestify\Tests\Fixtures\User\SampleUser; | ||
use Binaryk\LaravelRestify\Tests\Fixtures\User\User; | ||
use Binaryk\LaravelRestify\Tests\IntegrationTest; | ||
use Illuminate\Auth\Access\AuthorizationException; | ||
|
@@ -35,27 +32,6 @@ protected function setUp(): void | |
$this->authService = resolve(AuthService::class); | ||
} | ||
|
||
public function test_register_throw_user_not_authenticatable() | ||
{ | ||
$this->app->instance(User::class, (new class extends SampleUser implements Passportable { | ||
})); | ||
|
||
$user = [ | ||
'name' => 'Eduard Lupacescu', | ||
'email' => '[email protected]', | ||
'password' => 'password', | ||
'password_confirmation' => 'password', | ||
'remember_token' => Str::random(10), | ||
]; | ||
|
||
$request = new Request([], []); | ||
|
||
$request->merge($user); | ||
|
||
$this->expectException(AuthenticatableUserException::class); | ||
$this->authService->register($request); | ||
} | ||
|
||
public function test_user_query_throw_container_does_not_have_model_reflection_exception() | ||
{ | ||
$this->app['config']->set('auth.providers.users.model', null); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Binaryk\LaravelRestify\Tests\Fixtures\Post; | ||
|
||
use Binaryk\LaravelRestify\Contracts\RestifySearchable; | ||
use Binaryk\LaravelRestify\Repositories\Casts\RepositoryCast; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\Relations\Relation; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Collection; | ||
|
||
class RelatedCastWithAttributes extends RepositoryCast | ||
{ | ||
public static function fromBuilder(Request $request, Builder $builder): Collection | ||
{ | ||
return $builder->take($request->input('relatablePerPage') ?? (static::$defaultRelatablePerPage ?? RestifySearchable::DEFAULT_RELATABLE_PER_PAGE)) | ||
->get() | ||
->map(fn ($item) => ['attributes' => $item->toArray()]); | ||
} | ||
|
||
public static function fromRelation(Request $request, Relation $relation): Collection | ||
{ | ||
return $relation->take($request->input('relatablePerPage') ?? (static::$defaultRelatablePerPage ?? RestifySearchable::DEFAULT_RELATABLE_PER_PAGE)) | ||
->get() | ||
->map(fn ($item) => ['attributes' => $item->toArray()]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters