Skip to content

Instantly share code, notes, and snippets.

@ClaraLeigh
Created July 30, 2020 08:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ClaraLeigh/c253db5cd04cb3063802b4468408a636 to your computer and use it in GitHub Desktop.
Save ClaraLeigh/c253db5cd04cb3063802b4468408a636 to your computer and use it in GitHub Desktop.
Laravel Nova - Livewire Hack
Add middleware:
...
'mynova' => [
'web',
Authenticate::class,
DispatchServingNovaEvent::class,
BootTools::class,
Authorize::class,
]
...
(obviously add this to your routes)
@extends('admin.nova-livewire')
@section('body')
<div>
@livewire('example')
</div>
@endsection
@extends('nova::layout')
@section('content')
<loading ref="loading"></loading>
@yield('body')
@endsection
@push('header')
@livewireStyles
@endpush
@push('scripts')
<script>
window.addEventListener("click", function (event) {
var anchor = event.target.closest("a"); // Find closest Anchor (or self)
if (typeof anchor !== 'undefined' && anchor) {
window.location = anchor.getAttribute('href');
}
});
window.addEventListener( "pageshow", function ( event ) {
var historyTraversal = event.persisted ||
( typeof window.performance != "undefined" &&
window.performance.navigation.type === 2 );
if ( historyTraversal ) {
// Handle page restore.
window.location.reload();
}
});
history.replaceState({
livewire: true
}, document.title, window.location.pathname);
</script>
@livewireScripts
@endpush
Before `</head>` add:
@stack('header')
Before `</body>` add:
<script>
window.onpopstate = function(event) {
if (typeof event.state !== 'undefined' && typeof event.state["livewire"] !== 'undefined') {
location.reload();
}
};
</script>
@stack('scripts')
@ClaraLeigh
Copy link
Author

This is super hacky and probably riddled with bugs.
I made this because I have just moved to nova and don't have time to re-write my livewire components.

I hope this helps anyone trying to do the same thing or just get you somewhere as I couldn't figure out how to do it using cards or resource tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment