title: Returning javascript view in Laravel
body: <p>In Ruby on Rails In my controller I can do something like this:</p>
  
  <pre><code>def jstest
      respond_to do |format|
          format.js
      end
  end
  </code></pre>
  
  <p>This would return jstest.js.erb from the relevant views directory</p>
  
  <p>jstest.js.erb</p>
  
  <pre><code>alert("Hello World")
  </code></pre>
  
  <p>The result being I get hello world alert.</p>
  
  <p>I want to do the same thing in Laravel</p>
  
  <p>In my controller I have:</p>
  
  <pre><code>public function jstest(  )
  {
      return view('jstest');
  }
  </code></pre>
  
  <p>in my view (which I have tried with both jstest.blade.js and just jstest.js)</p>
  
  <p>but I get the error, view cannot be found.</p>
  
  <p>The only way I get this to work is by calling the view jstest.blade.php and including my js in a <code>&lt;script&gt;</code> tag within this php file. but this feels a bit wrong...?</p>
  
  <p>Is this even possible in Laravel? If so, where am I going wrong?</p>
  
  <hr>
  
  <p>Example use case:</p>
  
  <p>Imagine the following example, I have a table of comments, a user can click a delete button which will send an ajax request to delete the comment.</p>
  
  <p>My Route:</p>
  
  <pre><code>Route::delete('post/comments/{comment}','commentsController@delete');
  </code></pre>
  
  <p>In my controller:</p>
  
  <pre><code>Public Function delete($comment)
  {
      $comment-&gt;delete();
  
      return commentDeleted.js
  }
  </code></pre>
  
  <p>commentDeleted.js:</p>
  
  <pre><code>$(#comment).remove();
  </code></pre>
  
  <p>So from the users perspective, they click delete and the comment disappears from their screen without loading a new page.</p>