PHP Error - Noticed a non-existent constant 'x' being used in the code, assumed it to be 'x

How to Retrieve Data from a Table, Pass it to the Controller in JSON Format, and Display it in a View Using AngularJS

I am looking to extract data from a controller's json-encoded variable and showcase it on a view page through angularjs

<div class="card"  ng-app = "myApp">
  <table class="table table-hover" ng-controller = "menuController">
     <thead>
        <tr>
           <th>Name</th>
           <th>Parent menu</th>
           <th>Order</th>
           <th>Status</th>
           <th class="text-center">Actions</th>
        </tr>
     </thead>
     <tbody>
        <tr ng-repeat = "x  in values">
           <td>{{x.name}}</td>
           <td>{{x.parent_name}}</td>
           <td>{{x.orders}}</td>
           <td>{{x.status}}</td>
           <td class="text-right">
              <button type="button" class="btn btn-icon-toggle"
                      data-toggle="tooltip" data-placement="top"
                      data-original-title="Edit row">
                <i class="fa fa-pencil"></i>
              </button>
              <button type="button" class="btn btn-icon-toggle"
                      data-toggle="tooltip" data-placement="top"
                      data-original-title="Copy row">
                 <i class="fa fa-copy"></i>
              </button>
              <button type="button" class="btn btn-icon-toggle"
                      data-toggle="tooltip" data-placement="top" 
                      data-original-title="Delete row">
                <i class="fa fa-trash-o"></i>
              </button>
           </td>
        </tr>
     </tbody>
  </table>
</div>
 var app = angular.module('myApp');
  app.controller('menuController',function ($scope,$http) {
     $scope.values = ["Milk", "Bread", "Cheese"];
  });

Example of PHP Controller Code:

public function getmenu(){

    $records=Menu::all();

    return json_encode($records);
    }

Sample Route Code:

Route::group(['prefix'=>'admin'],function(){
    Route::get('/form','HomeController@form');
});

ErrorException (E_ERROR)
Use of undefined constant x - assumed 'x' (this will throw an Error in a future version of PHP) (View:form.blade.php)

Answer №1

It seems like the issue may arise from serving your view containing angular code with Laravel, and using angular syntax in the form.blade.php file.

To resolve this, consider removing the blade keyword from the view filename, changing it to form.php. Alternatively, when needing to display JavaScript framework content instead of blade, use: @{{ variableToPrint }}.

For instance, within a loop, you could adjust the syntax as follows:

<tr ng-repeat="x in values">
       <td>@{{x.name}}</td>
       <td>@{{x.parent_name}}</td>
       <td>@{x.orders}}</td>
       <td>@{{x.status}}</td>
       <!-- ... -->

The error occurs because blade interprets curly braces similarly to angular's syntax evaluation. To prevent conflicts, prefix variables with @ in Blade to differentiate instructions from literal values. This ensures proper execution of JavaScript loop code.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Controller is encountering an empty child array when attempting to JSON.stringify it

After examining numerous similar questions, I am uncertain about what sets my configuration apart. I've experimented with various ajax data variations and JSON formatting methods, but the current approach seems to be the closest match. This issue is ...

Angular JS can customize the default HTML page on a select tag, offering users a

When the web page is loaded, I want to display the default tableView.html from the views folder. However, it is not working as expected. Interestingly, when I switch between "Table View" and "List View" in the dropdown menu, it works fine. I believe the ...

Importing Laravel select2 library is necessary for enhancing user experience and improving

I've been attempting to incorporate select2 into my project without success. Every time I try these two methods, I always receive an error saying $('#state').select2 is not a function. However, when I include select2 in a standard <scrip ...

Troubleshooting the 'App Already Bootstrapped with this Element' Error in AngularJS

When I try to load my AngularJS app, I encounter the following error: Uncaught Error: [ng:btstrpd] App Already Bootstrapped with this Element '<html lang="en" ng-app="app" class="ng-scope">' I have only placed ng-app once in the html elem ...

angularjs Populate input fields with default values within ng-repeat loop

Our challenge is to display input text with pre-filled values within a list using the ng-repeat directive. <ul ng-repeat="post in postList> <input type="text" ng-model="postid" nginit="postid='{{post.id}}'"></input> </u ...

Generating arrays in the output of a Talend JSON field is essential for organizing and structuring

Having trouble with the tWriteJSONField component in Talend, specifically with pushing data into a tRESTClient object that has very specific API requirements. I can extract the required data using tWriteJSONField but it's not in the correct format tha ...

Having trouble converting JSON object to regular object?

I'm trying to change a JSON object into a regular object by using this method... var slaobj = eval('('+s+')'); However, it doesn't appear to be working correctly (the `.length' is returning as undefined). What m ...

Decoding GeoJSON: Extracting a feature from an array

I am currently working on a map project where I am drawing polygons with properties pulled from a JSON file. Each polygon is colored based on feature values in the JSON file. Here's an example of a feature in the JSON file: { "type": "Feature", " ...

Access the JSON data following its conversion from CSV format

I utilized the csv and json libraries to transform a csv file into a json file. The csv file consists of only one column: document "[{'param1': 'value1', 'param2': 'value2', 'param3': value3, 'par ...

Enable checkboxes to be pre-selected upon page loading automatically

Although I've found a lot of code snippets for a "select all" option, what I really need is more direct. I want the WpForms checkboxes to be pre-checked by default when the page loads, instead of requiring users to press a button. My goal is to have a ...

Angular Bootstrap uibModal is failing to resolve attributes

Issue with Roles in AngularJS Bootstrap uiModel var modalInstance = $uibModal.open({ animation: $scope.animationsEnabled, templateUrl: 'myModalContent.html', controller: 'ModalInstanceCtrl', size: 100, resolve: { roles: f ...

Mastering the art of inserting data using Zend 2's tableGateway

I have been using zf2's tableGateway and I am uncertain about the resulting design. Here is an example from zf2's documentation on how to use tableGateway for inserting data: public function saveAlbum(Album $album) { $data = array( ...

Unveiling the Mysteries of Running Imagick in PHP

I recently came across a helpful post discussing how to crop images in a circular shape. However, I am encountering issues when trying to run the imagemagick script using exec in PHP - no output is being generated. I have already verified that the director ...

AngularJS Bindings Problem

As a newcomer to AngularJS, I have been working on creating a todo list. Through my research on Google, I was able to write the code successfully. Whenever I click the add button, whatever I type into the textbox gets added to the list (UL /li). However, ...

[AWS Lambda SDK] - Executing Lambda Function - Processing Payload Response as Unit8Array - Conversion to String

Currently, I am utilizing the npm package @aws-sdk/client-lambda to invoke Lambdas. In my setup, I have two Lambdas - Lambda A and Lambda B, with Lambda A responsible for invoking Lambda B. The invocation of Lambda B from Lambda A is done through the foll ...

Executing a PHP command within the Symfony framework

I have recently transitioned from using Symfony 1 and NetBeans IDE to wanting to learn Symfony 2. In Netbeans, I was able to use Symfony commands with just a click. Now, I am eager to begin my journey with Symfony 2. You can find more information on Symf ...

The jQuery Mobile framework fails to initialize when loading data from an AJAX request in JSON format

I'm currently attempting to incorporate the jQuery Mobile 'styles' (specifically for buttons) into my project. Below is the HTML code snippet I am using (with Ajax): <!-- Using local jQuery + Mobile files --> <link rel="stylesheet ...

What is the best way to retrieve these values using PHP?

I am trying to retrieve and print the following fields: Id, Nombre_del_paciente__c, Fecha_de_la_cita__c, and Hora_de_la_cita__c This is the result of print_r($response);: Object ( [queryLocator] => [done] => 1 [records] => Array ( ...

Can the Angular link function activate the change event?

I am facing an issue with my Angular directive that includes a link function. Inside this function, I am initializing a jQuery plugin which can be seen in action here: https://plnkr.co/edit/58nOhypt6FRdI4At5jwu. The problem arises when every time the dire ...

Display all the ColumnB values for each value in columnA in a Python list

I have a dataframe where I need to merge two columns, one containing numeric IDs and the other strings. For example: https://i.stack.imgur.com/qcNCi.png My goal is to create a list showing all values in columnB for each value in columnA (below is an exce ...