mercredi 29 mars 2017

Returning javascript view in Laravel

In Ruby on Rails In my controller I can do something like this:

def jstest
    respond_to do |format|
        format.js
    end
end

This would return jstest.js.erb from the relevant views directory

jstest.js.erb

alert("Hello World")

The result being I get hello world alert.

I want to do the same thing in Laravel

In my controller I have:

public function jstest(  )
{
    return view('jstest');
}

in my view (which I have tried with both jstest.blade.js and just jstest.js)

but I get the error, view cannot be found.

The only way I get this to work is by calling the view jstest.blade.php and including my js in a <script> tag within this php file. but this feels a bit wrong...?

Is this even possible in Laravel? If so, where am I going wrong?



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

Aucun commentaire:

Enregistrer un commentaire