Turbolink is not working in Livewire version 2 - laravel

i am working on my new project and technology stack is: laravel 8 + Livewire V2 + Jetstream, to create a single page application (SPA). but I am still confused if its possible SPA in my selected technology stack or not.
I know Livewire no longer supports Turbolinks out of the box so they provided Turbolinks adapter. I have followed the documentation but seems like its not working. please help me to understand the issue and let me know if SPA is possible or not in Livewire version 2.
here is my code:
<div class="min-h-screen bg-gray-100">
#livewire('navigation-menu')
<!-- Page Heading -->
#if (isset($header))
<header class="bg-white shadow">
<div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
{{ $header }}
</div>
</header>
#endif
<!-- Page Content -->
<main>
{{ $slot }}
</main>
</div>
#stack('modals')
#livewireScripts
<script src="https://cdn.jsdelivr.net/gh/livewire/turbolinks#v0.1.x/dist/livewire-turbolinks.js" data-turbolinks-eval="false"></script>

Livewire Version 1 supported Turbolinks internally. Livewire Version 2 has removed internal support and extracted it into this plugin.
The goal of this livewire version 2 is to provide full Turbolinks/Turbo support in Livewire.
add hotwired/turbo package on your layout below #livewireScripts
add livewire/turbolinks package on your layout below hotwired/turbo package
#livewireScripts
<script type="module">
import hotwiredTurbo from 'https://cdn.skypack.dev/#hotwired/turbo';
</script>
<script src="https://cdn.jsdelivr.net/gh/livewire/turbolinks#v0.1.x/dist/livewire-turbolinks.js" data-turbolinks-eval="false" data-turbo-eval="false"></script>

You need to install Turbolink module first, Please go Turbolinks documentation Here.

Support for Turbolink has been removed in Livewire 2. So you need to add an extra JS script to make it work.
More here => https://github.com/livewire/turbolinks
Just add this after your livewire script:
<script src="https://cdn.jsdelivr.net/gh/livewire/turbolinks#v0.1.x/dist/livewire-turbolinks.js" data-turbolinks-eval="false" data-turbo-eval="false"></script>
Example:
#livewireScripts
<script src="https://cdn.jsdelivr.net/gh/livewire/turbolinks#v0.1.x/dist/livewire-turbolinks.js" data-turbolinks-eval="false" data-turbo-eval="false"></script>

Related

Logo on Navbar Won't Show in Laravel Jetstream

So I learn Laravel Jetstream using Inertia Stack. While I was doing some changing on Logo in the Navbar on Dashboard view it's still showing.
But when I go to profile view, it's just gone, I don't know why, but if I try using blade function which is asset function, it'll be gone in dashboard view too.
This is my code on ApplicationMark.vue:
<template>
<img class="block h-9 w-auto" src="favicon.png" alt="Logo">
<!-- <img class="block h-9 w-auto" src="{{ asset('favicon.png') }}" alt="Logo"> -->
</template>

Laravel and Vue: How do I get images from my public folder in a Vue component?

I am trying to get a logo image from my public folder in my laravel and Vue application. The file is called index.vue and have the following structure:
<template>
<div>
<div class="header-container">
<div class="header-content">
<div class="logo-container">
<img :src="'/public/images/logo/black.png'" alt="logo">
</div>
</div>
</div>
<!-- Tell Vue where to render components -->
<router-view></router-view>
</div>
</template>
Here is the file structure and you can see that file exists and the path is correct:
But when I switch back to the view it looks like this:
I have also tried to call it the way I would in a blade template using {{ asset() }}, but this doesn't work and gives me a compiler error.
How do I get this image to load in my Vue file?
Not sure about vue + laravel. But, since its a relative path I dont think you need to bind anything.
<img src="/images/logo/black.png" alt="logo">

Laravel session message as toastr notifications

How to convert the below session message to Toastr message without changing the controller code. In short i want to use toastr for all session messages without touching the controller code.
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif
I'm using basic bootstrap 4 and laravel 5.6
Since toastr is a JS library, it needs to be included on the page calling the snippet (either on the same page or before a .blade.php directive such as #include() or #yield()):
<script type="text/javascript" src="/path/to/toastr.js"></script>
Then, modify the snippet to use toastr:
#if(session("status"))
<script type="text/javascript">
toastr.info("{{ session("status") }}");
<script>
#endif
.blade.php will convert session("status") to a string, which toastr will process and display as an info message.
Great response from friend Tim Lewis, but I faced yet another challenge for trying to use the toatsr from the AdminLte3 template automatically installed on Laravel 6.x.
Below what I did to complement and make it work in my project.
According to the AminLte3 documentation, the additional inclusion of CSS or JS is through sections
Section example for adding CSS
#section('css')
<link rel="stylesheet" href="/css/admin_custom.css">
#stop
Section example for adding JS
#section('js')
<script> console.log('Hi!'); </script>
#stop
So I needed to add the Toastr library and then include my .blade file for alerts along with the JS section
JS section with the alerts .blade file
#section('js')
<script src="myPath/toastr.js"></script>
#include('myPath.alerts')
#stop
Alerts .blade file
#if(session("status"))
<script type="text/javascript">
toastr.info("{{ session("status") }}");
<script>
#endif

How can i create new blade in laravel 5.1

I just started using laravel and created a new login page. My issue is how can i create new blade.php file. When I copy the old one, my CSS file is used in the body. I want to make a new blade file. Also, can anyone suggest the best way to make login page.
<html>
<head>
{!! HTML::style('css/main.css') !!}
</head>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600' rel='stylesheet' type='text/css'>
<link href="//netdna.bootstrapcdn.com/font-awesome/3.1.1/css/font-awesome.css" rel="stylesheet">
<body>
<div class="form">
<ul class="tab-group">
<li class="tab active">Sign Up</li>
<li class="tab">Log In</li>
</ul>
<div class="tab-content">
<div id="signup">
<h1>Sign Up for Free</h1>
<form action="/" method="post">
<div class="top-row">
<div class="field-wrap">
<label>
First Name<span class="req">*</span>
</label>
<input type="text" required autocomplete="off" />
</div>
Blade templates are found on Resources/views folder. As suggested in the comment you just create a new file then add .blade.php extension to it.
blade files use html and if your comfortable with html5 tackle task as if you were writing plain html.
To get you started check this out http://laravel.com/docs/5.1/blade
Make sure you have installed laravelcollective/html
Follow the below steps,
add "laravelcollective/html": "5.1.*" in the require feild inside composer.json file in the root of the project.
Run composer update from root of your project. This will install the package required for blade templating by laravel.
In config/app.php, under providers add Collective\Html\HtmlServiceProvider::class.
In config/app.php, under aliases add 'Form'=>Collective\Html\FormFacade::class and
'Html'=>Collective\Html\HtmlFacade::class.
Thankyou :)

Godoc stylesheet and javascript

I know Godoc -html generates HTML only without stylesheets and javascript, but once generated where can I get those from?
I got css and js from godoc.org but it seems the js doesn't work with the html markup that is generated by godoc
I just want to try this out without using godoc server
Example markup:
<div id="pkg-overview" class="toggleVisible">
<div class="collapsed">
<h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
</div>
<div class="expanded">
<h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
<p>Hello World
</p>
</div>
</div>
You can try and have a look in tools#hg/godoc/static
You will find a godoc/static/godocs.js which might help.
It is used by godoc/static/godoc.html anyway.
godoc.html also uses:
godoc/static/style.css
godoc/static/jquery.treeview.css

Resources