2
votes

i follow this link
to create project hmvc in laravel
my structure file like this

+ [app]
  + [Another Directory]
  + [modules]
    + [content]
    + [shop]
      + [controllers]
        - ShopController.php
      + [view]
        - home.blade.php
      - route.php
      - ServiceProvider.php
    - ServiceProvider.php 
+ [Another Directory]

this is my shopController.php

<?php
namespace App\Modules\Shop\Controllers;

use App\Controllers\BaseController;
use View;

class ShopController extends BaseController {

    public function showWelcome() {
        return View::make('shop::home');
    }

}

and this is my route in shop module

<?php

Route::get('/shop', 'App\\Modules\\Shop\\Controllers\\ShopController@showWelcome');

i try to test return simple hello string from route in shop module and it's working

<?php 
Route::get('admin/shop', function() {
   return '<h1>Hello</h1>';
});

but where i'm missing
so can't display view from route or controller in hmvc


@update Jan.J

route in shop module

//this is working
Route::get('admin/shop', function() {
  return '<h1>hello</h1>';
});

//this is working, result laravel default page hello in view mvc
// but i can't dispay view in shop module
Route::get('admin/shop', function() {
  return View::make('hello');
});

//i try your script something like this, and it's not working
//correct me if i'm wrong
 Route::get('/shop', 'new App\Modules\Shop\Controllers\ShopController(app('request'));');

@update

i try to update my shop route to call view in shop module like this

<?php 
Route::get('test/', function() {
    return View::make(‘shop::home’);
});

and it's give result Class '‘shop' not found

any idea?

1
Maybe it's only typo here in question, but your directory is named [Module], but you refer to it like Modules. If your composer autoloading points to inexistent directory that would lead to those errors.Jan.J
@Jan.J yeah it's typo, my directory name is modules....but i refer it with Capital M, same with example in creolab...is that ok?Neversaysblack
Yes, classmap autoloading will take care of this. You could try to instantiate your controller somewhere else and see if class is being properly loaded. And before that run composer autoload.Jan.J
@Jan.J hm how about if i try to call view in module shop by route (route shop) first without controller...do you have idea how to do it..maybe from that i get fairy idea where i'm missingNeversaysblack
This should work: new App\Modules\Shop\Controllers\ShopController(app('request'));Jan.J

1 Answers

2
votes

Check controller class like that:

Route::get('/shop', function () {
    $controller = new App\Modules\Shop\Controllers\ShopController(app('request'));
    var_dump($controller);
});

Is it working? Do you see class dump? OR if not what error is displayed.