jeudi 19 avril 2018

PHP - Javascript - Laravel : JavaScript::put - Method not found

I'm trying to access data of my PHP from Javascript to format my page. I'm using Laravel framework.

IE : I'm storing some information in a database, I'm getting them from PHP, and I use these information to format my page differently according to the user logged. Informations in the DB are not used only for this purpose.

To format my page I'm using some JavaScript, so I need to access these data in my JavaScript.

I followed this tuto : https://github.com/laracasts/PHP-Vars-To-Js-Transformer

But I still can't access to my data, it's telling me that method put was not found in JavaScript.

Here is my bit of code:

file.blade.php :

@extends('layouts.app')
@section('content')
@include('footer')

<div class="container">
    Code for my page here. 
</div>

<script type="text/javascript">
    console.log(age);
</script>

@endsection

javascript.php:

<?php

return [
'bind_js_vars_to_this_view' => 'footer',
'js_namespace' => 'window'
];

controller.php:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\View\View;

use JavaScript;

class BusLine extends Model
{

public function index()
{

    JavaScript::put([
        'foo' => 'bar',
        'age' => 29
    ]);

    return View::make('hello');
}

protected $table='bus_line';

protected $fillable = [
    'ID', 'card_uid', 'bus_direction'
];
}

My footer.blade.php is empty, I added Laracasts\Utilities\JavaScript\JavaScriptServiceProvider::class and 'JavaScript' => Laracasts\Utilities\JavaScript\JavaScriptFacade::class, to app.php

I tried a few things like doing the PHP in another file and nothing changed. Always the same message. Maybe I've missed an installation step.

I'm totally new to Laravel / PHP so maybe my code is not structured correctly.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Hf359K
via IFTTT

Aucun commentaire:

Enregistrer un commentaire