File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -145,6 +145,25 @@ public function findById(string|int|PrimaryKey $id): object
145145 return $ this ->get ($ id );
146146 }
147147
148+ /**
149+ * Finds a model instance by its ID.
150+ *
151+ * **Example**
152+ * ```php
153+ * model(User::class)->resolve(1);
154+ * ```
155+ *
156+ * @return TModel
157+ */
158+ public function resolve (string |int |PrimaryKey $ id ): object
159+ {
160+ if (! inspect ($ this ->model )->hasPrimaryKey ()) {
161+ throw ModelDidNotHavePrimaryColumn::neededForMethod ($ this ->model , 'resolve ' );
162+ }
163+
164+ return $ this ->get ($ id );
165+ }
166+
148167 /**
149168 * Gets a model instance by its ID, optionally loading the given relationships.
150169 *
Original file line number Diff line number Diff line change @@ -59,7 +59,15 @@ public static function new(mixed ...$params): self
5959 */
6060 public static function findById (string |int |PrimaryKey $ id ): static
6161 {
62- return self ::resolve ($ id );
62+ return self ::get ($ id );
63+ }
64+
65+ /**
66+ * Finds a model instance by its ID.
67+ */
68+ public static function resolve (string |int |PrimaryKey $ id ): static
69+ {
70+ return model (self ::class)->resolve ($ id );
6371 }
6472
6573 /**
You can’t perform that action at this time.
0 commit comments