Muzammil Baloch
Muzammil Baloch

Reputation: 186

laravel - how to check auth guard in javascript?

in balde and controller when i want to get the authenticated admin i use

$data=Auth::guard('admin')->user();

is there a way to get this in a javascript variable and then console.log it?

i have tried to solve this by this but it doesn't work. I have also searched google and stackoverflow but cannot get an existing answer

var data = <?php Auth::guard('admin')->user();?>
console.log(data);

i'm using hesto multiauth

Upvotes: 0

Views: 1911

Answers (2)

Try this in your blade file:

<script>
   var data = {!! Auth::guard('admin')->user() !!}
   console.log(data);
</script>

Upvotes: 0

Muzammil Baloch
Muzammil Baloch

Reputation: 186

i solved the problem by doing this.

var data = <?= Auth::guard('customer')->user() ?>;

Upvotes: 1

Related Questions