-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from roelofr/feature/custom-alias-improvements
Improved custom namespace support
- Loading branch information
Showing
6 changed files
with
215 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Naoray\BlueprintNovaAddon\Tasks; | ||
|
||
use Closure; | ||
use Illuminate\Support\Str; | ||
use Naoray\BlueprintNovaAddon\Contracts\Task; | ||
|
||
class AddResourceImportIfRequired implements Task | ||
{ | ||
private string $resourceBaseClass; | ||
|
||
public function __construct(string $resourceBaseClass) | ||
{ | ||
$this->resourceBaseClass = $resourceBaseClass; | ||
} | ||
|
||
public function handle(array $data, Closure $next): array | ||
{ | ||
$baseNamespace = Str::beforeLast($this->resourceBaseClass, '\\'); | ||
|
||
$targetClass = $data['resource']; | ||
$targetNamespace = Str::beforeLast($targetClass, '\\'); | ||
|
||
if ($baseNamespace === $targetNamespace) { | ||
return $next($data); | ||
} | ||
|
||
$data['imports'][] = "use {$this->resourceBaseClass};"; | ||
|
||
return $next($data); | ||
} | ||
} |
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
4 changes: 4 additions & 0 deletions
4
tests/fixtures/definitions/nested-components-custom-namespace.bp
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,4 @@ | ||
models: | ||
Admin/User: | ||
name: string | ||
password: string |
101 changes: 101 additions & 0 deletions
101
tests/fixtures/nova/nested-components-custom-namespace.php
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,101 @@ | ||
<?php | ||
|
||
namespace App\Admin\Resources\Admin; | ||
|
||
use Laravel\Nova\Fields\ID; | ||
use Illuminate\Http\Request; | ||
use Laravel\Nova\Fields\Text; | ||
use App\Admin\Resources\Resource; | ||
use Laravel\Nova\Fields\DateTime; | ||
|
||
class User extends Resource | ||
{ | ||
/** | ||
* The model the resource corresponds to. | ||
* | ||
* @var string | ||
*/ | ||
public static $model = \App\Admin\User::class; | ||
|
||
/** | ||
* The single value that should be used to represent the resource when being displayed. | ||
* | ||
* @var string | ||
*/ | ||
public static $title = 'id'; | ||
|
||
/** | ||
* The columns that should be searched. | ||
* | ||
* @var array | ||
*/ | ||
public static $search = [ | ||
'id', | ||
]; | ||
|
||
/** | ||
* Get the fields displayed by the resource. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return array | ||
*/ | ||
public function fields(Request $request) | ||
{ | ||
return [ | ||
ID::make()->sortable(), | ||
|
||
Text::make('Name') | ||
->rules('required', 'string'), | ||
|
||
Text::make('Password') | ||
->rules('required', 'password'), | ||
|
||
DateTime::make('Created at'), | ||
DateTime::make('Updated at'), | ||
]; | ||
} | ||
|
||
/** | ||
* Get the cards available for the request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return array | ||
*/ | ||
public function cards(Request $request) | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* Get the filters available for the resource. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return array | ||
*/ | ||
public function filters(Request $request) | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* Get the lenses available for the resource. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return array | ||
*/ | ||
public function lenses(Request $request) | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* Get the actions available for the resource. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return array | ||
*/ | ||
public function actions(Request $request) | ||
{ | ||
return []; | ||
} | ||
} |