Skip to content

Instantly share code, notes, and snippets.

@bredmor
Created June 16, 2020 16:59
Show Gist options
  • Save bredmor/7e86ba3dfd9bcf28e36c5509c72f854c to your computer and use it in GitHub Desktop.
Save bredmor/7e86ba3dfd9bcf28e36c5509c72f854c to your computer and use it in GitHub Desktop.
Forwarding Laravel Nova GET parameters to filters/cards/metrics/etc.
// 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)};
}
});
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