0

[Edit]: I have read the suggested duplicate answer material, and my question is based on the work that I did using the variety of methods outlined there. I already found the answer, my problem was a typing error. Sad, but true.

[Question]: I have tried just about every set of instructions I can find on setting up a Helper class in Laravel 5.0; but something is still wrong because neither the autoload route or the namespace route are working. I only get a message such as "Class 'KidFit\Helpers\Helper.php not found'

What I also don't understand, is that when I include "$helper = new Helper();" statement into my UserController.php class -- that causes the php code of Helper.php to just get dumped to the screen. I have included an example of that in the screen output below. I don't have 10 rep points, so it appears to just be a link.

Here is what I get: Wonky Screen Output

I have nothing setup inside of config/app.php or composer.json. However, these are the contents of Helpers/Helper.php:

<$php
namespace KidFit\Helpers;

class Helper
{

        public function __construct()
        {

        }

        public function dominic()
        {
                \Log::info("dominic was here");
        }
}

and this is the code I have at the top of UserController.php, where I am using the Helper Class:

<?php namespace KidFit\Http\Controllers;

use KidFit\Http\Requests;
use KidFit\Http\Controllers\Controller;
use KidFit\User;
use KidFit\Games;
use KidFit\Helpers\Helper;

use Illuminate\Http\Request;

class UserController extends Controller {

        /**
         * Display the specified resource.
         *
         * @param  int  $id
         * @return Response
         */
        public function getShow($userID)
        {
                $helper = new Helper();
                \Log::info("Attempting to log data, DWayda");
                $Group = new Games;
                $Group->gameID = 4;
                $helper->dominic();
                //$Group->gameName = stripXSS("DROP TABLE user from KidFit_Secure;");
                $todaysDate = date_create('now');
                $todaysDate = date_format($todaysDate, 'Y-m-d');
                $Group->createDate = $todaysDate;
                $Group->metric = "SELECT * FROM users";
                $Group->status = "hacked";

                $Group->save();
                return User::find($userID);

        }

May I ask if I anyone can see what I am doing wrong? After my changes, I usually execute:

sudo composer dump-autoload
sudo composer install --no-dev --no-scripts
sudo composer install --no-dev -o

I've been stuck on this for 2 weeks now (working off & on...) Any help would e much appreciated!! =D

miken32
  • 42,008
  • 16
  • 111
  • 154
DWayda7021
  • 17
  • 3
  • Possible duplicate of [Best Practices for Custom Helpers in Laravel 5](https://stackoverflow.com/questions/28290332/best-practices-for-custom-helpers-in-laravel-5) – Udo E. Oct 12 '19 at 22:30
  • Replace `<$php` with ` – Clément Baconnier Oct 12 '19 at 22:31
  • @cbaconnier -- Thank you. I can't believe I was that stupid to miss this! This is exactly the problem, now every method works!!! – DWayda7021 Oct 12 '19 at 23:20
  • @UdoE. -- My code was based on the content there; this question is not a direct duplicate because the root issue was different. I think it would be valuable for others in case they are stuck like this too. I don't like admitting I made a stupid mistake like this, but they do happen to the best of us when we're not at our best. – DWayda7021 Oct 12 '19 at 23:23

1 Answers1

0

I owe an incredible thank you to cbaconnier for this answer in his comment. I can't believe I was that stupid. Now every method works... =')

Replace <\$php with <\php ? – cbaconnier 40 mins ago

DWayda7021
  • 17
  • 3