#Custom Package

36 messages · Page 1 of 1 (latest)

twin ether
#

Not to sure if I am doing this properly I made a directory in packages/company/blog my composer file has this:

    "require": {
        "php": "^8.0|^8.1",
        "spatie/laravel-package-tools": "^1.9.2",
        "filament/filament": "^2.0",
        "illuminate/contracts": "^8.0|^9.0",
        "filament/spatie-laravel-tags-plugin": "^2.0"
    },

in my root composer I have this

    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/",
            "Illusive\\Blog\\": "packages/company/blog/src/"
        }
    },

The package seems to have installed properly since the console commands are working properly, is there a better way to install it via root composer to get the child composer to install deps ?

violet burrow
twin ether
#

Yes you are correct its not adding it to the vendors folder

#

how would you "install" it from the local package directory so I can dev it?

violet burrow
#

You need to actually add your package’s name to the require section in your root composer.json file.

#

You then need to add a repositories section to tell Composer it can find that package in your local filesystem and not Git.

#

You also need to remove that entry from your autoload section.

twin ether
#

@violet burrow ok so by adding

        {
            "type": "path",
            "url": "./packages/illusive/blog",
            "options": {
                "symlink": true
            }
        }

I should be able to do composer require illusive/blog in cli, right now I am getting an error but want to make sure I got this setup properly first

violet burrow
#

If you’re getting an error it helps to post it.

twin ether
#

Could not find a matching version of package illusive/blog. Check the package spelling, your version constraint and that the package is available in a stability which matches your min
imum-stability (dev).

violet burrow
#

Instead of people having to constantly drag details out of you, which I’ve noticed a lot with your questions.

twin ether
#

hmm really I try to post as much as needed. Ill get better at putting more details into my questions.

{
    "name": "illusive/blog",
    "description": "Filament Blog Builder",
    "keywords": [
        "illusive",
        "laravel",
        "filament-blog",
        "blog"
    ],
    "homepage": "https://github.com/...",
    "license": "MIT",
    "authors": [
        {
            ...
        }
    ],
    "require": {
        "php": "^8.0|^8.1",
        "spatie/laravel-package-tools": "^1.9.2",
        "filament/filament": "^2.0",
        "illuminate/contracts": "^8.0|^9.0",
        "filament/spatie-laravel-tags-plugin": "^2.0"
    },
    "require-dev": {
        "nunomaduro/collision": "^5.10|^6.1",
        "orchestra/testbench": "^6.23|^7.0",
        "pestphp/pest": "^1.21",
        "pestphp/pest-plugin-laravel": "^1.1",
        "phpunit/phpunit": "^9.0|^9.5"
    },
    "autoload": {
        "psr-4": {
            "Illusive\\Blog\\": "src"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Illusive\\Blog\\Tests\\": "tests",
            "Illusive\\Blog\\Tests\\Database\\Factories\\": "tests/database/factories"
        }
    },
    "scripts": {
        "analyse": "vendor/bin/phpstan analyse",
        "test": "vendor/bin/pest",
        "test-coverage": "vendor/bin/pest --coverage"
    },
    "config": {
        "sort-packages": true,
        "allow-plugins": {
            "pestphp/pest-plugin": true
        }
    },
    "extra": {
        "laravel": {
            "providers": [
                "Illusive\\Blog\\BlogServiceProvider"
            ]
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}
#

package composer.json

violet burrow
#

If your package name and path is correct, Composer will find it.

#

If it’s not, then one of them is wrong.

#

I’ve done this myself with “local” packages many times in the past.

twin ether
#

got it, thank you @violet burrow

twin ether
#

In my package I have a controller called PostController

    /**
     * Display a listing of the resource.
     *
     * @return \Inertia\Response
     */
    public function index()
    {
        $posts = Post::all();

        return Inertia::render('Home', compact('posts'));
    }
#

The problem is that it seems like the HandleInertiaRequests middleware is not applied to this controller even though its in the root apps kernel.php

#

Do packages not have the web middleware group?

violet burrow
twin ether
#

ahh I needed to apply the web middleware to make it work

violet burrow
twin ether
#

ohh no I wasnt the handleInertiaRequests middleware is in my app kernel

#

and I was confused as to why the web.php routes in my package were not utilizing those middlewares but it needs to be specificially set it seems

#
<?php

use Illuminate\Support\Facades\Route;
use Illusive\Blog\Http\Controllers\PostController;
use Illusive\Blog\Http\Controllers\TagController;

Route::group(['middleware' => config('jetstream.middleware', ['web'])], function () {
    Route::prefix('blog')->group(function () {
        Route::resource('post', PostController::class)->parameters(['post' => 'slug']);
        Route::resource('tag', TagController::class)->parameters(['tag' => 'slug']);
    });
});

rather then just having the route::prefix ...

twin ether
#

@violet burrow when you are developing your package how do you setup the environment, what I have been doing is adding a sub module via git and mapping it to packages/illusive/blog testing it locally then committing changes to the package and removing the sub module but this doesn't seem like the proper way.

Then I was thinking of making a blank laravel install and then adding a submodule there but I am guessing there is a better way.

violet burrow
#

Obviously you’ll need to run git init in the root of the package’s directory. And then you can git push when the package is in a state to be committed and pushed.

#

Also gitignore the package’s directory from your root app.

twin ether
#

well now that the package is "done" and I can install it on my other projects I pushed it up to git and added it to repositories in composer.json. Moving forward is what I was trying to figure out

violet burrow
twin ether
#

yeah thats working fine, I got the package into my project, what I am trying to figure out is how you setup the ongoing dev of the package. Do you load it into another project, blank project with a git submodule and push that way?

#

or when you need to make a change/update do you load the git submodule into the project you are working on make the update repush to git so all the other projects get access to it