2222use Illuminate \Contracts \Routing \Registrar as RegistrarContract ;
2323use Illuminate \Routing \Route as IlluminateRoute ;
2424use Illuminate \Routing \RouteCollection ;
25+ use LaravelJsonApi \Contracts \Schema \Schema ;
2526use LaravelJsonApi \Core \Support \Str ;
2627
2728class RelationshipRegistrar
@@ -32,6 +33,11 @@ class RelationshipRegistrar
3233 */
3334 private RegistrarContract $ router ;
3435
36+ /**
37+ * @var Schema
38+ */
39+ private Schema $ schema ;
40+
3541 /**
3642 * @var string
3743 */
@@ -51,17 +57,20 @@ class RelationshipRegistrar
5157 * RelationshipRegistrar constructor.
5258 *
5359 * @param RegistrarContract $router
60+ * @param Schema $schema
5461 * @param string $resourceType
5562 * @param string $controller
5663 * @param string $parameter
5764 */
5865 public function __construct (
5966 RegistrarContract $ router ,
67+ Schema $ schema ,
6068 string $ resourceType ,
6169 string $ controller ,
6270 string $ parameter
6371 ) {
6472 $ this ->router = $ router ;
73+ $ this ->schema = $ schema ;
6574 $ this ->resourceType = $ resourceType ;
6675 $ this ->controller = $ controller ;
6776 $ this ->parameter = $ parameter ;
@@ -95,7 +104,7 @@ public function register(string $fieldName, bool $hasMany, array $options = []):
95104 */
96105 protected function addShowRelated (string $ fieldName , array $ options ): IlluminateRoute
97106 {
98- $ uri = $ this ->getRelationshipUri ($ fieldName, $ options );
107+ $ uri = $ this ->getRelationshipUri ($ fieldName );
99108 $ action = $ this ->getRelationshipAction (
100109 'showRelated ' ,
101110 'showRelated ' . Str::classify ($ fieldName ),
@@ -120,7 +129,7 @@ protected function addShowRelated(string $fieldName, array $options): Illuminate
120129 */
121130 protected function addShowRelationship (string $ fieldName , array $ options ): IlluminateRoute
122131 {
123- $ uri = $ this ->getRelationshipUri ($ fieldName, $ options );
132+ $ uri = $ this ->getRelationshipUri ($ fieldName );
124133 $ action = $ this ->getRelationshipAction (
125134 'showRelationship ' ,
126135 'show ' . Str::classify ($ fieldName ),
@@ -145,7 +154,7 @@ protected function addShowRelationship(string $fieldName, array $options): Illum
145154 */
146155 protected function addUpdateRelationship (string $ fieldName , array $ options ): IlluminateRoute
147156 {
148- $ uri = $ this ->getRelationshipUri ($ fieldName, $ options );
157+ $ uri = $ this ->getRelationshipUri ($ fieldName );
149158 $ action = $ this ->getRelationshipAction (
150159 'updateRelationship ' ,
151160 'update ' . Str::classify ($ fieldName ),
@@ -170,7 +179,7 @@ protected function addUpdateRelationship(string $fieldName, array $options): Ill
170179 */
171180 protected function addAttachRelationship (string $ fieldName , array $ options ): IlluminateRoute
172181 {
173- $ uri = $ this ->getRelationshipUri ($ fieldName, $ options );
182+ $ uri = $ this ->getRelationshipUri ($ fieldName );
174183 $ action = $ this ->getRelationshipAction (
175184 'attachRelationship ' ,
176185 'attach ' . Str::classify ($ fieldName ),
@@ -195,7 +204,7 @@ protected function addAttachRelationship(string $fieldName, array $options): Ill
195204 */
196205 protected function addDetachRelationship (string $ fieldName , array $ options ): IlluminateRoute
197206 {
198- $ uri = $ this ->getRelationshipUri ($ fieldName, $ options );
207+ $ uri = $ this ->getRelationshipUri ($ fieldName );
199208 $ action = $ this ->getRelationshipAction (
200209 'detachRelationship ' ,
201210 'detach ' . Str::classify ($ fieldName ),
@@ -277,16 +286,11 @@ private function getRelationshipAction(
277286
278287 /**
279288 * @param string $fieldName
280- * @param array $options
281289 * @return string
282290 */
283- private function getRelationshipUri (string $ fieldName, array $ options ): string
291+ private function getRelationshipUri (string $ fieldName ): string
284292 {
285- if (isset ($ options ['relationship_uri ' ])) {
286- return $ options ['relationship_uri ' ];
287- }
288-
289- return Str::dasherize ($ fieldName );
293+ return $ this ->schema ->relationship ($ fieldName )->uriName ();
290294 }
291295
292296 /**
0 commit comments