How to get foreach in controller into table view in blade laravel
I have been trying to get data from google analytics in laravel. It will show the pathpage and the pageviews in a form of table. I have retrieved the data using spatie/laravel-analytics but when I display it on the view the page views is not tally to the google analytics. So I have been trying to sort the data using the following code but keep getting errors
Here is my controller:
public function google(MediaSite $mediaSite)
{
$ga7day = Analytics::performQuery(
Period::days(7),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$ga1month = Analytics::performQuery(
Period::days(30),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$ga3month = Analytics::performQuery(
Period::months(3),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$analyticsDataToday = Analytics::performQuery(
Period::days(7),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$mediaSite = new MediaSite;
$mediaSite = MediaSite::Where('media_owner_id','1');
foreach ($mediaSite as $site)
$site->view7days = 0;
foreach ($ga7day as $ga)
# code...
if($ga['1'] === '/media-site/'. $site->id);
$site->view7days = $ga['3'];
# code...
$site->view1month = 0;
foreach ($ga1month as $mga)
# code...
if($mga['1'] === '/media-site/'. $site->id);
$site->view1month = $mga['3'];
# code...
$site->view3month = 0;
foreach ($ga3month as $nga)
# code...
if($nga['1'] === '/media-site/' . $site->id);
$site->view3month = $nga['3'];
# code...
return
view('analytics.google',compact('ga7day','ga1month','ga3month',
'analyticsDataToday','site','mediaSite','ga','mga','nga'));
my view:
<body>
<form method="get" action=" action('AnalyticsController@google') ">
csrf_field()
<div class="input-group">
<input type="text" name="q" class="form-control" placeholder="eg: Media Ownner" required>
<span class="input-group-btn">
<button type="submit" class="btn btn-default">
Go!
</button>
</span>
</div>
</form>
<br>
<br>
<table class="table">
<tr>
<th> Media Site </th>
<th> 7 days</th>
<th> 1 month</th>
<th> 3 month</th>
<th> Overall</th>
</tr>
<tr>
@foreach ($ga as $index => $key)
<tr> <td> $key['1'] </td>
<td> $key['3'] </td>
<td> $ga1month[$index]['3'] </td>
<td> $ga3month[$index]['3'] </td>
<td> $analyticsDataToday[$index]['3'] </td></tr>
@endforeach
</tr>
</table>
</body>
</html>
I keep getting these errors:
enter image description here
php laravel google-analytics pageviews
add a comment |
I have been trying to get data from google analytics in laravel. It will show the pathpage and the pageviews in a form of table. I have retrieved the data using spatie/laravel-analytics but when I display it on the view the page views is not tally to the google analytics. So I have been trying to sort the data using the following code but keep getting errors
Here is my controller:
public function google(MediaSite $mediaSite)
{
$ga7day = Analytics::performQuery(
Period::days(7),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$ga1month = Analytics::performQuery(
Period::days(30),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$ga3month = Analytics::performQuery(
Period::months(3),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$analyticsDataToday = Analytics::performQuery(
Period::days(7),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$mediaSite = new MediaSite;
$mediaSite = MediaSite::Where('media_owner_id','1');
foreach ($mediaSite as $site)
$site->view7days = 0;
foreach ($ga7day as $ga)
# code...
if($ga['1'] === '/media-site/'. $site->id);
$site->view7days = $ga['3'];
# code...
$site->view1month = 0;
foreach ($ga1month as $mga)
# code...
if($mga['1'] === '/media-site/'. $site->id);
$site->view1month = $mga['3'];
# code...
$site->view3month = 0;
foreach ($ga3month as $nga)
# code...
if($nga['1'] === '/media-site/' . $site->id);
$site->view3month = $nga['3'];
# code...
return
view('analytics.google',compact('ga7day','ga1month','ga3month',
'analyticsDataToday','site','mediaSite','ga','mga','nga'));
my view:
<body>
<form method="get" action=" action('AnalyticsController@google') ">
csrf_field()
<div class="input-group">
<input type="text" name="q" class="form-control" placeholder="eg: Media Ownner" required>
<span class="input-group-btn">
<button type="submit" class="btn btn-default">
Go!
</button>
</span>
</div>
</form>
<br>
<br>
<table class="table">
<tr>
<th> Media Site </th>
<th> 7 days</th>
<th> 1 month</th>
<th> 3 month</th>
<th> Overall</th>
</tr>
<tr>
@foreach ($ga as $index => $key)
<tr> <td> $key['1'] </td>
<td> $key['3'] </td>
<td> $ga1month[$index]['3'] </td>
<td> $ga3month[$index]['3'] </td>
<td> $analyticsDataToday[$index]['3'] </td></tr>
@endforeach
</tr>
</table>
</body>
</html>
I keep getting these errors:
enter image description here
php laravel google-analytics pageviews
3
Please reduce your code to the minimum needed to solve your problem
– Lithilion
Nov 12 '18 at 7:27
Before thisreturn view('analytics.google',compact('ga7day','ga1month','ga3month', 'analyticsDataToday','site','mediaSite','ga','mga','nga'));
Can you output the value of ga, something like return $ga. I bellieve this value is not defined in your code.
– Elie
Nov 12 '18 at 7:47
How to define $ga? I don't really understand my code actually. I just search for various info on google. Do you mean dd() or print_r()?
– Adilah Abdullah
Nov 12 '18 at 7:52
I tried return $ga but I still get the same error
– Adilah Abdullah
Nov 12 '18 at 7:52
add a comment |
I have been trying to get data from google analytics in laravel. It will show the pathpage and the pageviews in a form of table. I have retrieved the data using spatie/laravel-analytics but when I display it on the view the page views is not tally to the google analytics. So I have been trying to sort the data using the following code but keep getting errors
Here is my controller:
public function google(MediaSite $mediaSite)
{
$ga7day = Analytics::performQuery(
Period::days(7),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$ga1month = Analytics::performQuery(
Period::days(30),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$ga3month = Analytics::performQuery(
Period::months(3),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$analyticsDataToday = Analytics::performQuery(
Period::days(7),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$mediaSite = new MediaSite;
$mediaSite = MediaSite::Where('media_owner_id','1');
foreach ($mediaSite as $site)
$site->view7days = 0;
foreach ($ga7day as $ga)
# code...
if($ga['1'] === '/media-site/'. $site->id);
$site->view7days = $ga['3'];
# code...
$site->view1month = 0;
foreach ($ga1month as $mga)
# code...
if($mga['1'] === '/media-site/'. $site->id);
$site->view1month = $mga['3'];
# code...
$site->view3month = 0;
foreach ($ga3month as $nga)
# code...
if($nga['1'] === '/media-site/' . $site->id);
$site->view3month = $nga['3'];
# code...
return
view('analytics.google',compact('ga7day','ga1month','ga3month',
'analyticsDataToday','site','mediaSite','ga','mga','nga'));
my view:
<body>
<form method="get" action=" action('AnalyticsController@google') ">
csrf_field()
<div class="input-group">
<input type="text" name="q" class="form-control" placeholder="eg: Media Ownner" required>
<span class="input-group-btn">
<button type="submit" class="btn btn-default">
Go!
</button>
</span>
</div>
</form>
<br>
<br>
<table class="table">
<tr>
<th> Media Site </th>
<th> 7 days</th>
<th> 1 month</th>
<th> 3 month</th>
<th> Overall</th>
</tr>
<tr>
@foreach ($ga as $index => $key)
<tr> <td> $key['1'] </td>
<td> $key['3'] </td>
<td> $ga1month[$index]['3'] </td>
<td> $ga3month[$index]['3'] </td>
<td> $analyticsDataToday[$index]['3'] </td></tr>
@endforeach
</tr>
</table>
</body>
</html>
I keep getting these errors:
enter image description here
php laravel google-analytics pageviews
I have been trying to get data from google analytics in laravel. It will show the pathpage and the pageviews in a form of table. I have retrieved the data using spatie/laravel-analytics but when I display it on the view the page views is not tally to the google analytics. So I have been trying to sort the data using the following code but keep getting errors
Here is my controller:
public function google(MediaSite $mediaSite)
{
$ga7day = Analytics::performQuery(
Period::days(7),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$ga1month = Analytics::performQuery(
Period::days(30),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$ga3month = Analytics::performQuery(
Period::months(3),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$analyticsDataToday = Analytics::performQuery(
Period::days(7),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$mediaSite = new MediaSite;
$mediaSite = MediaSite::Where('media_owner_id','1');
foreach ($mediaSite as $site)
$site->view7days = 0;
foreach ($ga7day as $ga)
# code...
if($ga['1'] === '/media-site/'. $site->id);
$site->view7days = $ga['3'];
# code...
$site->view1month = 0;
foreach ($ga1month as $mga)
# code...
if($mga['1'] === '/media-site/'. $site->id);
$site->view1month = $mga['3'];
# code...
$site->view3month = 0;
foreach ($ga3month as $nga)
# code...
if($nga['1'] === '/media-site/' . $site->id);
$site->view3month = $nga['3'];
# code...
return
view('analytics.google',compact('ga7day','ga1month','ga3month',
'analyticsDataToday','site','mediaSite','ga','mga','nga'));
my view:
<body>
<form method="get" action=" action('AnalyticsController@google') ">
csrf_field()
<div class="input-group">
<input type="text" name="q" class="form-control" placeholder="eg: Media Ownner" required>
<span class="input-group-btn">
<button type="submit" class="btn btn-default">
Go!
</button>
</span>
</div>
</form>
<br>
<br>
<table class="table">
<tr>
<th> Media Site </th>
<th> 7 days</th>
<th> 1 month</th>
<th> 3 month</th>
<th> Overall</th>
</tr>
<tr>
@foreach ($ga as $index => $key)
<tr> <td> $key['1'] </td>
<td> $key['3'] </td>
<td> $ga1month[$index]['3'] </td>
<td> $ga3month[$index]['3'] </td>
<td> $analyticsDataToday[$index]['3'] </td></tr>
@endforeach
</tr>
</table>
</body>
</html>
I keep getting these errors:
enter image description here
php laravel google-analytics pageviews
php laravel google-analytics pageviews
edited Nov 12 '18 at 7:59
Adilah Abdullah
asked Nov 12 '18 at 7:26
Adilah AbdullahAdilah Abdullah
84
84
3
Please reduce your code to the minimum needed to solve your problem
– Lithilion
Nov 12 '18 at 7:27
Before thisreturn view('analytics.google',compact('ga7day','ga1month','ga3month', 'analyticsDataToday','site','mediaSite','ga','mga','nga'));
Can you output the value of ga, something like return $ga. I bellieve this value is not defined in your code.
– Elie
Nov 12 '18 at 7:47
How to define $ga? I don't really understand my code actually. I just search for various info on google. Do you mean dd() or print_r()?
– Adilah Abdullah
Nov 12 '18 at 7:52
I tried return $ga but I still get the same error
– Adilah Abdullah
Nov 12 '18 at 7:52
add a comment |
3
Please reduce your code to the minimum needed to solve your problem
– Lithilion
Nov 12 '18 at 7:27
Before thisreturn view('analytics.google',compact('ga7day','ga1month','ga3month', 'analyticsDataToday','site','mediaSite','ga','mga','nga'));
Can you output the value of ga, something like return $ga. I bellieve this value is not defined in your code.
– Elie
Nov 12 '18 at 7:47
How to define $ga? I don't really understand my code actually. I just search for various info on google. Do you mean dd() or print_r()?
– Adilah Abdullah
Nov 12 '18 at 7:52
I tried return $ga but I still get the same error
– Adilah Abdullah
Nov 12 '18 at 7:52
3
3
Please reduce your code to the minimum needed to solve your problem
– Lithilion
Nov 12 '18 at 7:27
Please reduce your code to the minimum needed to solve your problem
– Lithilion
Nov 12 '18 at 7:27
Before this
return view('analytics.google',compact('ga7day','ga1month','ga3month', 'analyticsDataToday','site','mediaSite','ga','mga','nga'));
Can you output the value of ga, something like return $ga. I bellieve this value is not defined in your code.– Elie
Nov 12 '18 at 7:47
Before this
return view('analytics.google',compact('ga7day','ga1month','ga3month', 'analyticsDataToday','site','mediaSite','ga','mga','nga'));
Can you output the value of ga, something like return $ga. I bellieve this value is not defined in your code.– Elie
Nov 12 '18 at 7:47
How to define $ga? I don't really understand my code actually. I just search for various info on google. Do you mean dd() or print_r()?
– Adilah Abdullah
Nov 12 '18 at 7:52
How to define $ga? I don't really understand my code actually. I just search for various info on google. Do you mean dd() or print_r()?
– Adilah Abdullah
Nov 12 '18 at 7:52
I tried return $ga but I still get the same error
– Adilah Abdullah
Nov 12 '18 at 7:52
I tried return $ga but I still get the same error
– Adilah Abdullah
Nov 12 '18 at 7:52
add a comment |
1 Answer
1
active
oldest
votes
Replace your controller with the following
public function google(MediaSite $mediaSite)
$ga7day = Analytics::performQuery( Period::days(7),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$ga1month = Analytics::performQuery( Period::days(30),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$ga3month = Analytics::performQuery( Period::months(3),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$analyticsDataToday = Analytics::performQuery( Period::days(7),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$mediaSite = new MediaSite;
$mediaSite = MediaSite::Where('media_owner_id','1');
foreach ($mediaSite as $site)
$site->view7days = 0;
foreach ($ga7day as $ga)
# code...
if($ga['1'] === '/media-site/'. $site->id);
$site->view7days = $ga['3'];
# code...
$site->view1month = 0;
foreach ($ga1month as $mga)
# code...
if($mga['1'] === '/media-site/'. $site->id);
$site->view1month = $mga['3'];
# code...
$site->view3month = 0;
foreach ($ga3month as $nga)
# code...
if($nga['1'] === '/media-site/' . $site->id);
$site->view3month = $nga['3'];
# code...
return view('analytics.google',compact('mediaSite'));
And in the view
@foreach ($meadiaSite as $site)
<tr>
<td> $site['1'] </td>
<td> $site->view7days </td>
<td> $site->view1month </td>
<td> $site->view3month </td>
<td> /*same logic*/ </td>
</tr>
@endforeach
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257533%2fhow-to-get-foreach-in-controller-into-table-view-in-blade-laravel%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Replace your controller with the following
public function google(MediaSite $mediaSite)
$ga7day = Analytics::performQuery( Period::days(7),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$ga1month = Analytics::performQuery( Period::days(30),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$ga3month = Analytics::performQuery( Period::months(3),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$analyticsDataToday = Analytics::performQuery( Period::days(7),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$mediaSite = new MediaSite;
$mediaSite = MediaSite::Where('media_owner_id','1');
foreach ($mediaSite as $site)
$site->view7days = 0;
foreach ($ga7day as $ga)
# code...
if($ga['1'] === '/media-site/'. $site->id);
$site->view7days = $ga['3'];
# code...
$site->view1month = 0;
foreach ($ga1month as $mga)
# code...
if($mga['1'] === '/media-site/'. $site->id);
$site->view1month = $mga['3'];
# code...
$site->view3month = 0;
foreach ($ga3month as $nga)
# code...
if($nga['1'] === '/media-site/' . $site->id);
$site->view3month = $nga['3'];
# code...
return view('analytics.google',compact('mediaSite'));
And in the view
@foreach ($meadiaSite as $site)
<tr>
<td> $site['1'] </td>
<td> $site->view7days </td>
<td> $site->view1month </td>
<td> $site->view3month </td>
<td> /*same logic*/ </td>
</tr>
@endforeach
add a comment |
Replace your controller with the following
public function google(MediaSite $mediaSite)
$ga7day = Analytics::performQuery( Period::days(7),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$ga1month = Analytics::performQuery( Period::days(30),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$ga3month = Analytics::performQuery( Period::months(3),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$analyticsDataToday = Analytics::performQuery( Period::days(7),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$mediaSite = new MediaSite;
$mediaSite = MediaSite::Where('media_owner_id','1');
foreach ($mediaSite as $site)
$site->view7days = 0;
foreach ($ga7day as $ga)
# code...
if($ga['1'] === '/media-site/'. $site->id);
$site->view7days = $ga['3'];
# code...
$site->view1month = 0;
foreach ($ga1month as $mga)
# code...
if($mga['1'] === '/media-site/'. $site->id);
$site->view1month = $mga['3'];
# code...
$site->view3month = 0;
foreach ($ga3month as $nga)
# code...
if($nga['1'] === '/media-site/' . $site->id);
$site->view3month = $nga['3'];
# code...
return view('analytics.google',compact('mediaSite'));
And in the view
@foreach ($meadiaSite as $site)
<tr>
<td> $site['1'] </td>
<td> $site->view7days </td>
<td> $site->view1month </td>
<td> $site->view3month </td>
<td> /*same logic*/ </td>
</tr>
@endforeach
add a comment |
Replace your controller with the following
public function google(MediaSite $mediaSite)
$ga7day = Analytics::performQuery( Period::days(7),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$ga1month = Analytics::performQuery( Period::days(30),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$ga3month = Analytics::performQuery( Period::months(3),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$analyticsDataToday = Analytics::performQuery( Period::days(7),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$mediaSite = new MediaSite;
$mediaSite = MediaSite::Where('media_owner_id','1');
foreach ($mediaSite as $site)
$site->view7days = 0;
foreach ($ga7day as $ga)
# code...
if($ga['1'] === '/media-site/'. $site->id);
$site->view7days = $ga['3'];
# code...
$site->view1month = 0;
foreach ($ga1month as $mga)
# code...
if($mga['1'] === '/media-site/'. $site->id);
$site->view1month = $mga['3'];
# code...
$site->view3month = 0;
foreach ($ga3month as $nga)
# code...
if($nga['1'] === '/media-site/' . $site->id);
$site->view3month = $nga['3'];
# code...
return view('analytics.google',compact('mediaSite'));
And in the view
@foreach ($meadiaSite as $site)
<tr>
<td> $site['1'] </td>
<td> $site->view7days </td>
<td> $site->view1month </td>
<td> $site->view3month </td>
<td> /*same logic*/ </td>
</tr>
@endforeach
Replace your controller with the following
public function google(MediaSite $mediaSite)
$ga7day = Analytics::performQuery( Period::days(7),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$ga1month = Analytics::performQuery( Period::days(30),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$ga3month = Analytics::performQuery( Period::months(3),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$analyticsDataToday = Analytics::performQuery( Period::days(7),
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth, ga:pagePath',
]
);
$mediaSite = new MediaSite;
$mediaSite = MediaSite::Where('media_owner_id','1');
foreach ($mediaSite as $site)
$site->view7days = 0;
foreach ($ga7day as $ga)
# code...
if($ga['1'] === '/media-site/'. $site->id);
$site->view7days = $ga['3'];
# code...
$site->view1month = 0;
foreach ($ga1month as $mga)
# code...
if($mga['1'] === '/media-site/'. $site->id);
$site->view1month = $mga['3'];
# code...
$site->view3month = 0;
foreach ($ga3month as $nga)
# code...
if($nga['1'] === '/media-site/' . $site->id);
$site->view3month = $nga['3'];
# code...
return view('analytics.google',compact('mediaSite'));
And in the view
@foreach ($meadiaSite as $site)
<tr>
<td> $site['1'] </td>
<td> $site->view7days </td>
<td> $site->view1month </td>
<td> $site->view3month </td>
<td> /*same logic*/ </td>
</tr>
@endforeach
answered Nov 12 '18 at 8:08
Elie Elie
24737
24737
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257533%2fhow-to-get-foreach-in-controller-into-table-view-in-blade-laravel%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Please reduce your code to the minimum needed to solve your problem
– Lithilion
Nov 12 '18 at 7:27
Before this
return view('analytics.google',compact('ga7day','ga1month','ga3month', 'analyticsDataToday','site','mediaSite','ga','mga','nga'));
Can you output the value of ga, something like return $ga. I bellieve this value is not defined in your code.– Elie
Nov 12 '18 at 7:47
How to define $ga? I don't really understand my code actually. I just search for various info on google. Do you mean dd() or print_r()?
– Adilah Abdullah
Nov 12 '18 at 7:52
I tried return $ga but I still get the same error
– Adilah Abdullah
Nov 12 '18 at 7:52