11 months ago

Unable to clear cache for custom package

Posted 11 months ago by dvdmeer


I am creating my own package but am currently stuck at some weird caching stuff. My custom package is copied into my sample project that I created with:

composer create-project laravel/laravel --prefer-dist sample

The package has the following folder structure:



My main composer.json file looks like this:

    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
    "license": "MIT",
    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "5.7.*",
        "laravel/tinker": "^1.0",
        "dvdmeer/testpackage": "*"
    "require-dev": {
        "beyondcode/laravel-dump-server": "^1.0",
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.0"
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    "extra": {
        "laravel": {
            "dont-discover": []
    "autoload": {
        "psr-4": {
            "App\": "app/"
        "classmap": [
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
    "repositories": [
            "type": "path",
            "url": "./testpackage"
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "@php artisan package:discover --ansi"
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"

When I run composer update it does see my package so no problem there. I checked with the dd command in some strategic places in my ServiceProvider and it does execute. Here is my ServiceProvider code:


namespace TestPackage;

use TestPackage\Commands\TestPackageInstall;
use TestPackage\Preset;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Console\PresetCommand;

class TestPackageServiceProvider extends ServiceProvider
     * Register services.
     * @return void
    public function register()

     * Bootstrap services.
     * @return void
    public function boot()

        if ($this->app->runningInConsole()) {

        PresetCommand::macro('testing', function($command) {


    private function setupMigrations() {
        // Set up extra migrations

    private function setupRoutes() {
        // Set up extra routes

    private function setupViews() {
        // Set up extra views
        $this->loadViewsFrom(__DIR__.'/views', 'testpackage');

    private function setupResources() {
            __DIR__.'/resources' => public_path('testpackage'),
        ], 'public');

My custom routes file looks like this:


Route::get('/assets', function() {
    return "we are here!";
/*Route::get('/admin/assets/{params}', 'TestPackage\Http\Controllers\[email protected]')->where('params', '.*');*/

Route::get('/admin', function () {
    return view('testpackage::home');

Note that I have commented out most of it because of some testing. I have created a separate assets route because I do not want to publish any of my css and images into the public folder in my sample project but leave them in my package. That way I have everything contained.

I have a separate controller that manages the assets (found this on StackOverflow somewhere):


namespace TestPackage\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Response;

class AssetsController extends \App\Http\Controllers\Controller
     * Get asset url and return response based on file type
     * @param $filename
     * @return mixed
    public function data($filename)

        $path = __DIR__ . '/../../resources/';
        $path =  $path . $filename;

        $file = File::get($path);
        $type = File::mimeType($path);

        $response = Response::make($file, 200);

        // For some reason it does not recognize css correctly so I force it
        if (strpos($filename, '.css') !== false) {
            $response->header("Content-Type", "text/css");
        } else {
            $response->header("Content-Type", $type);

        return $response;

Apart from the fact that css is always returned as text/plain instead of text/css it does work (with my corrections) so this way I can keep everything separate.

I had it running once but noticed that when I change my custom routes it still keeps going to my blade file even though I have commented out the route (and checked with php artisan route:list that it is not there anymore) and my assets route does nothing.

I tried the following commands to clear my cache:

php artisan route:cache
composer clearcache

I ran composer update again but nothing seems to help. Stopping my php artisan serve command and starting it again also doesn't work.

What am I doing wrong here?

Please sign in or create an account to participate in this conversation.