samedi 1 juillet 2017

Laravel Controllers __construct Issue

So I am having a few dramas with my controllers. They seem to operate properly, however they don't seem to use __construct() at all in any of the controllers.. I'm trying to use this to update our users table to show last activity.

<?php

namespace App\Http\Controllers;

use Illuminate\Routing\Controller as BaseController;
use Illuminate\Http\Request;
use App\Helpers\UserHelper;
use App\Helpers\ForumHelper;
use App\Helpers\ShopHelper;
use Auth;
use Image;
use App\User;
use DB;
use Hash;
use File;

class AdminController extends BaseController
{

public function __construct() {
  if ($_SERVER["HTTP_CF_CONNECTING_IP"]) {
    $_SERVER["REMOTE_ADDR"] = $_SERVER["HTTP_CF_CONNECTING_IP"];
  }

  if(Auth::check()) {
    $time = strtotime("now");
    DB::table('users')->where('userid', Auth::user()->userid)->update(['lastactivity' => $time]);
  }

}

Any idea what I can do to check and try and get it working again?

I'm running Laravel Framework 5.4.28

A project I did similar on was running Laravel Framework version 5.2.45 and worked fine when I was doing that so I'm confused why this is happening on a newer version.

Any ideas how I can otherwise go about implementing the DB Update when loading stuff from my controllers?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire