Created
June 16, 2020 16:59
-
-
Save bredmor/7e86ba3dfd9bcf28e36c5509c72f854c to your computer and use it in GitHub Desktop.
Forwarding Laravel Nova GET parameters to filters/cards/metrics/etc.
This file contains hidden or 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
// All parameter keys defined here will be forwarded to all subsequent requests on this page. | |
let forward_params = [ | |
'market_id', | |
]; | |
function get(name){ | |
// Credit https://stackoverflow.com/a/831060/1451408 | |
if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search)) { | |
return decodeURIComponent(name[1]); | |
} | |
} | |
forward_params.forEach((param) => { | |
if(param) { | |
axios.defaults.params = {[param]: get(param)}; | |
} | |
}); |
This file contains hidden or 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
class NovaServiceProvider extends NovaApplicationServiceProvider | |
{ | |
/** | |
* Bootstrap any application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
parent::boot(); | |
Nova::script('forward-params', public_path('js/forward-params.js')); | |
} | |
//...etc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment