0
votes

Here is my application structure,

my-first-app
   |    
   |-app
     |
     | -Commands
     | -Console
     | -Events
     | -Http
     | -models(custom define folder)
        |
        |-Base(folder)
        |   |
        |   | -StuDetails.php
        |   | -StuDetailsQuery.php
        |
        |-Map(foder)
        |-StuDetails.php
        |-StuDetailsQuery.php

Actually I'm using propel ORM to retrieve data from the database. I created my model classes inside the folder models. Then I tried to access StudetailsQuery class inside my pageController class which is inside http folder extended as Controller.

Here it is :

<?php
namespace App\models\propel;
namespace App\Http\Controllers;


use App\Http\Requests;
use App\Http\Controllers\Controller;


use Base\StuDetailsQuery;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;

class pagesController extends Controller
{


    public function index()
    {
        $stu= StuDetailsQuery::create()->find();
        return view('pages.index', compact('stu'));
    } 

But I get error :

PHP Fatal error: Class 'Base\StuDetailsQuery' not found in /var/www/my-first-app/app/Http/Controllers/pagesController.php

I tried;

  • composer dump-autoload
  • adding following lines to composer.json file

    "autoload": { "psr-4":{ "propel\": "app/models/propel/" }}

but nothing goes fine for me.. Any suggestions please ??

2

2 Answers

1
votes
"autoload": {
        "classmap": [
            "database",
            "app/models/propel"
        ]

this solved my problem... :)

0
votes

I keep getting similar missing class errors. Although I follow the laracast autoloading examples in You Must Use Composer laracast completely (including the modification of composer.json), I get stuck with a missing class error.

In watching the videos I notices jeffery way uses a \ occasionally before the object name..... I don't know why but in frustration I added it, and it worked for me.

In summary I find I have to use a "\" before the object, like this:

new \Bar;

I hope this helps, and if someone can help me understand what is going on please let us know.