Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rafaeladi's avatar

unexpected double-quoted string error

Im creating a dashboard using laravel, now i want to call the test results that i already stored in my database but it keeps showing this error

syntax error, unexpected double-quoted string "test_name", expecting identifier or variable or "{" or "$" (View: C:\xampp\htdocs\autoDash\resources\views\results\overview_details.blade.php)

I already use dump and dd to debug it and it shows that the data is already there but everytime that i want to show it in my view page with a foreach function, it always shows this error. how can i fix this?

Here is my controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ResultsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        // View the overview page
        $data=[];

        $data=DB::table('test_name')->get();
        // dd($data);

        return view ('results/overview_details',['test_name'=>$data]);
    }

Here is my view

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

@extends('layout/main')

@section('title', "Test Results")

@section('contents')
  <div class='container'>
  <div class="row">
  <div class="col-12">
  <h1 class="mt-3 mb-3">Overview Details</h1>
  <nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
  <ol class="breadcrumb">
  <li class="breadcrumb-item"><a href="{{url('/')}}">Overview</a></li>
  <li class="breadcrumb-item active" aria-current="page">Overview Details</li>
  </ol>
  </nav>

  <table class="table table-hover">
  <thead>
  <tr>
  <th scope="col">Test Case</th>
  <th scope="col">Configuration</th>
  <th scope="col">Version No.</th>
  <th scope="col">Status</th>
  </tr>
  </thead>
  <tbody>
  @foreach ($data as $value)
  <tr>
  <th scope="row" class='col-3'><a href="/details">{{$value->test_name}}</a></th>
   <td class='col-4'>{{$value->config}}</td>
   <td class='col-2'>{{$value->version}}</td>
   </tr>
   @endforeach
   </tbody>

And here is my routes:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ResultsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        // View the overview page
        $data=[];

        $data=DB::table('test_name')->get();
        // dd($data);

        return view ('results/overview_details',['test_name'=>$data]);
    }

And im working on laravel 8.29.0

0 likes
7 replies
Snapey's avatar

Your code does not stack up

You are passing $test_name to the view and then iterating over $data

So, with the code you show, I can't see how you get that error and not undefined $data

rafaeladi's avatar

but what i mean is the 'test_name' is the name of the field on the DB that it should passed on

Snapey's avatar

sure. thats not what your code does - at least not this code

rafaeladi's avatar

why not? is it because im not using eloquent and models? maybe you can point out where i did my code wrong

Snapey's avatar
return view ('results/overview_details',['test_name'=>$data]);

This creates a variable in the view called $test_name with the value of whatever is in $data

rafaeladi's avatar
 $data=DB::table('test_name')->get();
        // dd($data);

        return view ('results/overview_details',['test_name'=>$data]);

And the data that i want to passed on to my view page is based on the data from my table in my DB which also called 'test_name'. this is why i am so confused about this problem, i looked on the documentation that this is the correct way to write the code but it doesnt seem to work while i saw a guy on YT did the same thing and he managed to passed the data.

Snapey's avatar

you query the database into a variable called $data

You pass that data to the view within a variable called $test_name

The name of your table in the database is not relevant.

If this is not clear, I suggest some more training and experimentation.

The point is, in the view, you are doing @foreach ($data as $value) but you do not have $data

Please or to participate in this conversation.