Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Laravel, Axios & Logout Over AJAX
import React from 'react';
import ReactDOM from 'react-dom';
const handleLogout = () => {'/logout')
.then(() => location.href = '/home')
function Example() {
return (
<div className="container">
<div className="row justify-content-center">
<div className="col-md-8">
<div className="card">
<div className="card-header">Example Component</div>
<div className="card-body">
<p className="card-text">I'm an example component!</p>
<button className="btn btn-light" onClick={handleLogout}>Logout</button>
export default Example;
if (document.getElementById('example')) {
ReactDOM.render(<Example />, document.getElementById('example'));
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Example Component</div>
<div class="card-body">
<p class="card-text">I'm an example component.</p>
<a class="btn btn-light" @click="logout">Logout</a>
export default {
methods: {
logout() {'/logout')
.then(() => location.href = '/home')
mounted() {
console.log('Component mounted.')
namespace App\Http\Controllers\Auth;
use ...
class LoginController extends Controller
* The user has logged out of the application.
* @param \Illuminate\Http\Request $request
* @return mixed
protected function loggedOut(Request $request)
if ($request->wantsJson()) {
return response()->json([], 204);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment