Print JavaScript variable value inside php tag using click template in Laravel

Suppose this is JS code and I want to print the value id. Here id is a variable with a value that takes in a jq function.

function follow_or_unfollow(id,action){         
     myUrl = "{{ action('FollowsController@show', 'id') }}" ;               
}

If we stretch 'id', it will show the id string.

PS. here {{uses, as implied by the php code in the blade template.

Now I need to print the script variable inside php code.

+4
source share
3 answers

I am afraid that what you ask is impossible. The simple reason is that JavaScript is client-side and PHP is server-side.

PHP- JavaScript, . JavaScript PHP, , , , .

Update

. , JS URL-, PHP $_GET.

+2

, , , .

myUrl = "{{ action('FollowsController@show', 'id') }}" ;

javascript. javascript, . , PHP script. :

myUrl = "@include("public.default.js_values.myUrl")" ;

(in your views folder)/public/default/js_values/myUrl.blade.php

{{ action('FollowsController@show', 'id') }}

, myUrl.blade.php. , php ( ) javascript.

, .

+1

{!! $vars!!}.

var link = {!! "'".url('string/'.$vars.'/string')."'" !!};
0

All Articles