laravel-5 passing variable to JavaScript

前端 未结 6 1101
慢半拍i
慢半拍i 2020-11-30 00:26

is there any ways that JavaScript can get the variable from compact controller Laravel-5.

Example: I have the code below:

   $langs = Language::all()         


        
6条回答
  •  甜味超标
    2020-11-30 01:03

    One working example for me.

    Controller:

    public function tableView()
    {
        $sites = Site::all();
        return view('main.table', compact('sites'));
    }
    

    View:

    
    

    To prevent malicious / unintended behaviour, you can use JSON_HEX_TAG as suggested by Jon in the comment that links to this SO answer

    
    

提交回复
热议问题