How to get foreach in controller into table view in blade laravel










0















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










share|improve this question



















  • 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















0















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










share|improve this question



















  • 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













0












0








0








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










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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












  • 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







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












1 Answer
1






active

oldest

votes


















0














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





share|improve this answer






















    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
    );



    );













    draft saved

    draft discarded


















    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









    0














    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





    share|improve this answer



























      0














      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





      share|improve this answer

























        0












        0








        0







        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





        share|improve this answer













        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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 '18 at 8:08









        Elie Elie

        24737




        24737





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

            Crossroads (UK TV series)

            ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế