0

Overview:

I've Laravel project with a Laravel-Module a Laravel Package for Modularizing the project. The Laravel Project routes are working. However, In Laravel-Module action() and url() Helpers methods showing function doesn't exist while it exist.


Problem Statement:

Unable to direct to Laravel-Module Controller using action() and url() method

From AType_Controller.php

namespace Modules\Test\Http\Controllers;

class AType_Controller extends Controller
{
    public function testFunc()
    {
        url(
            action('\Modules\Test\Http\Controllers\BType_Controller@index'),
            )

InvalidArgumentException Action Modules\Test\Http\Controllers\BType_Controller@index not defined.


Folder Structure:

project-root/
├─ app/
│  └─ Http/
│       └─ Controllers/
├─ bootstrap/
├─ config/
├─ database/
├─ Modules/
|   └─ Test/
|       └─ Config/
|       └─ Console/
|       └─ Database/
|       └─ Entities/
|       └─ Http/
|           └─ Controllers/
|               └─ AType_Controller.php
|               └─ BType_Controller.php
|       └─ Notifications/
|       └─ Providers/
|       └─ Resources/
|       └─ Utils/
|       └─ composer.json
|       └─ module.json
|       └─ package.json
├─ public/
│  └─ index.php
├─ resources/
├─ routes/
├─ storage/
├─ vendor/
├─ .env
└─ composer.json

composer.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": "^8.0.2",
        "consoletvs/charts": "^7.2",
        "laravel/framework": "^8.29",
        "laravel/tinker": "^2.6",
        "laravel/ui": "^3.2",
        "nwidart/laravel-menus": "^7.0",
        "nwidart/laravel-modules": "^8.2",
    },
    "autoload": {
        "files": [
            "app/Http/helpers.php"
        ],
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/",
            "Modules\\": "Modules/"
        }
    },
    

Edit 1:

  1. I've publish the package configuration by running
php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
  1. And edited my composer.json to add Modules in autoload using ps-4.

  2. Run the composer dump-autoload command.


Edit 2:

$ php artisan tinker

Psy Shell v0.10.6 (PHP 8.0.2 — cli) by Justin Hileman
>>> (new Modules\Test\Entities\Document)->foo()
=> "foo"

Document.php

<?php

namespace Modules\Test\Entities;
use Illuminate\Database\Eloquent\Model;

class Document extends Model
{
    public function foo()
    {
        return 'foo';
    }

Edit 3:

$ php artisan module:v6:migrate

All modules have been migrated.
+---------------+---------+
| Module name   | Status  |
+---------------+---------+
| Essentials    | Enabled |
| Manufacturing | Enabled |
| Superadmin    | Enabled |
| Woocommerce   | Enabled |

This command create modules_statuses.json under Laravel Project.


4
  • 1
    does your composer.json happen to have this package? github.com/nWidart/laravel-modules Commented Feb 25, 2021 at 10:15
  • @AnuratChapanond, Yes it does have. Let me put my composer.json in question. Commented Feb 25, 2021 at 10:17
  • 1
    then it uses Laravel module to separate codes into modules and I happen to know it but never use it so you should read its documentation. Commented Feb 25, 2021 at 10:20
  • @AnuratChapanond, For identifying the correct Laravel Package been used. Commented Feb 25, 2021 at 10:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.