Thursday, March 16, 2017

From jQuery to blade variable

I know how to pass variables from blade template to jQuery modal, but I don't see how to do it other way around. I can check if the user is for example registered with:

@if(\Illuminate\Support\Facades\Auth::user())
    open modal with options
@else
    open basic modal message "you are not authorized"
@endif

But now, I'd like to check if the registered user is available to use the equipment on which he clicked. I have all the necessary model relations, so I could do something like Auth::user()->equipment->where('equipment_id', $equipment->id) != null...but the problem is that I can forward a variable to jQuery like data-equipment-id = ... and fetch it within a script...but how do I get it back to PHP variable so I can access it like:

@if(\Illuminate\Support\Facades\Auth::user())
    @if(Auth::user()->equipment->where('equipment_id', $equipment->id) != null)
        allowed!
    @else
        not allowed!
    @endif
@else
    open basic modal message "you are not authorized"
@endif



via Norgul

Advertisement