File tree Expand file tree Collapse file tree
src/Illuminate/Database/Eloquent/Relations Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,6 +28,13 @@ class MorphTo extends BelongsTo {
2828 */
2929 protected $ dictionary = array ();
3030
31+ /*
32+ * Indicates if soft-deleted model instances must be fetched or not
33+ *
34+ * @var bool
35+ */
36+ protected $ withTrashed = false ;
37+
3138 /**
3239 * Create a new belongs to relationship instance.
3340 *
@@ -150,6 +157,11 @@ protected function getResultsByType($type)
150157 {
151158 $ instance = $ this ->createModelByType ($ type );
152159
160+ if ($ this ->withTrashed && $ instance ->newQuery ()->getMacro ('withTrashed ' ) !== null )
161+ {
162+ $ instance = $ instance ->withTrashed ();
163+ }
164+
153165 $ key = $ instance ->getKeyName ();
154166
155167 return $ instance ->whereIn ($ key , $ this ->gatherKeysByType ($ type )->all ())->get ();
@@ -193,4 +205,16 @@ public function getDictionary()
193205 return $ this ->dictionary ;
194206 }
195207
208+ /**
209+ * Fetch soft-deleted model instances with query
210+ *
211+ * @return MorphTo
212+ */
213+ public function withTrashed ()
214+ {
215+ $ this ->withTrashed = true ;
216+
217+ return $ this ;
218+ }
219+
196220}
You can’t perform that action at this time.
0 commit comments