Skip to content

Instantly share code, notes, and snippets.

@aquasmit
Created December 15, 2016 12:01
Show Gist options
  • Save aquasmit/03307fd2abb5771c6d7ea543467af68d to your computer and use it in GitHub Desktop.
Save aquasmit/03307fd2abb5771c6d7ea543467af68d to your computer and use it in GitHub Desktop.
Laravel - Passing variables to JavaScript

Controller:

public function tableView()
{

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

Views:

<script>    
var sites = {!! json_encode($sites->toArray()) !!};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment