After posting unable to get to comments section

Following a tutorial on thinkster on building a simple page where you can post titles and links and comment on your posts.

After clicking post my title is posted with a comments link. However when I click on the comments link nothing happens.

Here is my index.html:

  <title>Flapper News</title>
  <link href="" rel="stylesheet">
  <style> .glyphicon-thumbs-up { cursor:pointer } </style>
<body ng-app="flapperNews">
{{post.upvotes}} {{post.title}} {{post.title}} Comments

Add a new post

{{comment.upvotes}} - by {{}} {{comment.body}}

Add a new comment

</body> </html>

And here is my app.js page:

var app = angular.module('flapperNews', ['ui.router']); 

function($stateProvider, $urlRouterProvider) {

    .state('home', {
      url: '/home',
      templateUrl: '/home.html',
      controller: 'MainCtrl'

      url: '/posts{id}',
      templateUrl: '/posts.html',
      controller: 'PostsCtrl'


app.factory('posts', [function(){
  var o = {
  return o;

app.controller('MainCtrl', [    
function($scope, posts){
  $scope.test = 'Hello world!';

  $scope.posts = posts.posts;

 $scope.addPost = function(){
  if(!$scope.title || $scope.title === '') { return; }
    title: $scope.title, 
    link: $,
    upvotes: 0,
    comments: [
    {author: 'Joe', body: 'Cool post!', upvotes: 0},
    {author: 'Bob', body: 'Great idea but everything is wrong!', upvotes: 0}
  $scope.title = '';
  $ = '';

 $scope.incrementUpvotes = function(post) {
  post.upvotes += 1;

app.controller('PostsCtrl', [
function($scope, $stateParams, posts){
  $ = posts.posts[$];

  $scope.addComment = function(){
  if($scope.body === '') { return; }
    body: $scope.body,
    author: 'user',
    upvotes: 0
  $scope.body = '';

Source: stackoverflow-javascript

Laravel 5 – Conditionally append variables

A few words before

I know that you can append variables to model arrays and json representations by using the protected $appends = ["your", "vars", "here"]; array. But imagine the following situation:

The situation

Our use case would be a fictional game or similiar:

Imagine that we have a User model that holds simple information about an (human) user, like the full name, address and so on.

Now, we also have a Faction model that represents the faction/origin/guild/… of this user.

The Faction model is eager-loaded when retrieving users, because the Faction name is wanted almost every time when displaying the user information.

A User also has DailyStatistics, which holds some information about their daily scores (simple points would be enough).

The Clue

Because I want to know the points of the a faction, which is the sum of the user points, I thought about appending a new variable totalPoints.

The getTotalPointsAttribute function would look like this:

function getTotalPointsAttribute(){
    return $this->users->sum->getTotalPoints();

The problem

Everytime when we retrieve a user now, the eager-loaded faction would also want to calculate the totalPoints attribute. That means, that we have a lot of overhead per user.

The question

Is there a way to avoid situations like this? Can I “conditionally” append variables? Are properties calculated when they are hidden?

I tried to wrap the totalPoints variable in a simple function, instead of an accessor instead. The problem is, that Frontend-Frameworks like VueJS would need access to the totalPoints variable (or to an endpoint to retrieve that value, but this solution is the least favorable).

Source: stackoverflow-php

Onclick function is not called in JavaScript

I spent significant time on solving one issue in JavaScript. The code snippet is as bellow. The details of other part of html, Form and Table is omitted in this post.

<input id="btn" type="button" value="Save Customer" onclick="SaveData" />

function BindData(Data)
    //This removes all other rows except first
    //More logic is there to fill a table

function SaveData()
    $("#status").text("Adding data. Please wait......");
    var frm = $("#frmCustomer").serialize();
    $.post("Submit", frm, BindData);

Source: stackoverflow-javascript

change laravel 5.4 text mail content-type to text/plain

I am sending a small text mail with laravel:

public function build()
    return $this->text('emails.empty')->subject($this->msg)

The view empty.blade.php should only print the message:

{{ $msg }}

But neomutt receives text/html content:

[-- text/html wird nicht unterst├╝tzt ('v' benutzen, um diesen Teil anzuzeigen) --]

and thunderbird also shows text/html instead of plain text:

MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

What can I do to get the mail so that neomutt does not complain?
I guess I need text/plain.

Source: stackoverflow-php

Is it possible to specify a cache validator for a PHP file that serves JS content?

I’ve tried various methods and so far have the following in .htaccess:

ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresDefault "access plus 1 month"

# 1 month exp
ExpiresActive On
<filesMatch ".(gpdf|PDF|gif|ico|jpg|jpeg|png|GIF|ICO|JPG|JPEG|PNG|css|js|woff|CSS|JS|WOFF|ttf|TTF|txt|TXT|html|HTML)$">
  Header unset Set-Cookie
  Header set Cache-Control "max-age=2592000"
  Header unset ETag
  FileETag None

And the PHP file that serves the JS content has the following headers:

header('Content-type: application/javascript');
header("Cache-control: max-age=2592000, must-revalidate");

When I go to do a speed-test it still shows “specify a cache validator for js.php”

Is what I’m doing even possible or am I just missing something?

Source: stackoverflow-php

Write json file to Firebase with Node.js?

I have a third party API that I need to call every 5 seconds. I get JSON as response, and I’d like to write the JSON content to a Firebase node using Node.js. Based on Firebase examples I could import data with this code:

var usersRef = ref.child("users");
  alanisawesome: {
    date_of_birth: "June 23, 1912",
    full_name: "Alan Turing"
  gracehop: {
    date_of_birth: "December 9, 1906",
    full_name: "Grace Hopper"

Curl examples worked too. But what I really wanted to do is to import a third party API response directly to my Firebase database using the API endpoint. How can i do it with Node.js?

Source: stackoverflow-javascript

Find and replace <?php & ?> in string

I have a large string of valid HTML code that will be inserted into the DOM, the string also contains PHP code. I want the php code to be displayed as plain text, Chrome automatically comments out the PHP code. Obviously the PHP code is wrapped in <?php ... ?> so my question is:

How can I replace the open <?php with a <span> tag, and replace the ?> with a </span> to close the open <span> tag so that the PHP code is within the <span> tags and therefor visible as plain text?

EDIT: I will be wrapping the PHP code back in <?php ?> by replacing the span, so escaping the characters will make that more difficult.

Source: stackoverflow-javascript

Php Server: HTTP_X_FORWARDED_SSL usage

In OpenCart i saw the following code:

    // Check if SSL
if ((isset($_SERVER['HTTPS']) && (($_SERVER['HTTPS'] == 'on') || ($_SERVER['HTTPS'] == '1'))) || (isset($_SERVER['HTTPS']) &&    $_SERVER['SERVER_PORT'] == 443)) {
    $_SERVER['HTTPS'] = true;
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
    $_SERVER['HTTPS'] = true;
} else {
    $_SERVER['HTTPS'] = false;

What is $_SERVER[‘HTTP_X_FORWARDED_PROTO’] or $_SERVER[‘HTTP_X_FORWARDED_SSL’]? I could’t find them in PHP Manual.

Source: stackoverflow-php