@@ -91,6 +91,88 @@ public function to($path, $extra = array(), $secure = null)
91
91
return $ this ->trimUrl ($ root , $ path , $ tail );
92
92
}
93
93
94
+ /**
95
+ * Generate a secure, absolute URL to the given path.
96
+ *
97
+ * @param string $path
98
+ * @param array $parameters
99
+ * @return string
100
+ */
101
+ public function secure ($ path , $ parameters = array ())
102
+ {
103
+ return $ this ->to ($ path , $ parameters , true );
104
+ }
105
+
106
+ /**
107
+ * Generate a URL to an application asset.
108
+ *
109
+ * @param string $path
110
+ * @param bool|null $secure
111
+ * @return string
112
+ */
113
+ public function asset ($ path , $ secure = null )
114
+ {
115
+ if ($ this ->isValidUrl ($ path )) return $ path ;
116
+
117
+ // Once we get the root URL, we will check to see if it contains an index.php
118
+ // file in the paths. If it does, we will remove it since it is not needed
119
+ // for asset paths, but only for routes to endpoints in the application.
120
+ $ root = $ this ->getRootUrl ($ this ->getScheme ($ secure ));
121
+
122
+ return $ this ->removeIndex ($ root ).'/ ' .trim ($ path , '/ ' );
123
+ }
124
+
125
+ /**
126
+ * Remove the index.php file from a path.
127
+ *
128
+ * @param string $root
129
+ * @return string
130
+ */
131
+ protected function removeIndex ($ root )
132
+ {
133
+ $ i = 'index.php ' ;
134
+
135
+ return str_contains ($ root , $ i ) ? str_replace ('/ ' .$ i , '' , $ root ) : $ root ;
136
+ }
137
+
138
+ /**
139
+ * Generate a URL to a secure asset.
140
+ *
141
+ * @param string $path
142
+ * @return string
143
+ */
144
+ public function secureAsset ($ path )
145
+ {
146
+ return $ this ->asset ($ path , true );
147
+ }
148
+
149
+ /**
150
+ * Get the scheme for a raw URL.
151
+ *
152
+ * @param bool|null $secure
153
+ * @return string
154
+ */
155
+ protected function getScheme ($ secure )
156
+ {
157
+ if (is_null ($ secure ))
158
+ {
159
+ return $ this ->forceSchema ?: $ this ->request ->getScheme ().':// ' ;
160
+ }
161
+
162
+ return $ secure ? 'https:// ' : 'http:// ' ;
163
+ }
164
+
165
+ /**
166
+ * Force the schema for URLs.
167
+ *
168
+ * @param string $schema
169
+ * @return void
170
+ */
171
+ public function forceSchema ($ schema )
172
+ {
173
+ $ this ->forceSchema = $ schema .':// ' ;
174
+ }
175
+
94
176
/**
95
177
* Get the URL to a named route.
96
178
*
0 commit comments