Use of undefined constant analyticsData - assumed 'analyticsData' (this will throw an Error in a future version of PHP) (View: /home/vagrant/apps/rt2018/resources/views/records.blade.php) (View: /home/vagrant/apps/rt2018/resources/views/records.blade.php)"
My records.blade.php file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello Analytics - A quickstart guide for JavaScript</title>
</head>
<body>
<h1>Hello Analytics</h1>
{{analyticsData}}
</body>
</html>
My Controller
use Spatie\Analytics\Period;
use Analytics;
public function showMonthlyReport($site_id, $report_id){
$reports = Report::where('report_id', $report_id)->firstOrFail();
$analyticsData = Analytics::fetchMostVisitedPages(Period::days(7));
return view('records', compact('site_id', 'report_id', 'reports', 'analyticsData'));
}
This is my blade file path to records.blade.php
<a href="{{route('Reports',['site_id'=>$report->site_id, 'report_id'=>$report->report_id])}}">view</a>
I tried to put any variable in my controller. For example $wow = 1;
Add 'wow' on return view on my controller
And put it to my blade {{wow}} is giving me the same error.
This is working before but I don't know what happen.
Any {{object}}
that put on my blade give me this error. Use of undefined constant (any declared object)
. When I tried to delete/comment out the analyticsData and also in my blade file it was working. It was working on Laravel 5.2 and PhP 7.2 before now I'm using Laravel 5.4. I know its not because the version. Do you have any idea how to fix this? Thank you in advance!
{{analyticsData}}
should be{{ $analyticsData }}
, although it might not output correctly; but that's a different issue. – Tim Lewis{{ products }}
- Undefined Constant,{{ $products }}
-[]
(is an empty array). You did add the$
right? I didn't just adjust the spacing (as spacing doesn't matter, just for readability). – Tim Lewis.blade.php
file? I don't know of any instance where{{ anything }}
would work without you defininganything
as a global constant; you're not referencing with$
, so you should (and are) gettingUndefined constant ...
– Tim Lewis