Laravel Spark 11 - edit Spark source files not working anymore - laravel

Dear Sparkers/Laravellers
I am transforming an old Spark project (i believe version 6) to the latest version 11.
To make some changes in the Spark PHP files, I've copied the files under vendor/laravel/spark-aurelius to a newly created folder named spark. Next, I've changed in the composer.json:
"repositories": [
{
"type": "composer",
"url": "https://spark-satis.laravel.com"
}
]
to
"repositories": [
{
"type": "path",
"url": "./spark"
}
]
Thereby notifying Laravel/Spark that it should use the files in the spark folder. Also, I've changed
"laravel/spark-aurelius": "~11.0",
to
"laravel/spark-aurelius": "*#dev",
Since that was something that was done in my original older Spark installation.
Next, I performed a composer update (lots of changes) until it finished.
However, when I make some test changes to the routes.php in Spark/src/Http/routes.php and save them it's not working. The old routes are still used.
I've also cleared cache:
php artisan optimize:clear
php artisan route:clear
php artisan config:clear
php artisan cache:clear
php artisan view:clear
Any other tips?

Well, there was only step missing (not mentioned in the original documentation!). So it appears we need to remove the complete vendor folder before doing composer update.
If you perform this task, and then go to the vendor/laravel folder and do ls -al you'll discover that the spark folder is now nicely referenced to the one that was provided:
spark-aurelius -> ../../spark

Related

Laravel 8 on App Engine: "Please provide a valid cache path"

I upgraded a Laravel project from version 7 to 8. When I attempt to deploy it on App Engine, it fails saying "Please provide a valid cache path":
Updating service [***]...failed.
ERROR: (gcloud.app.deploy) Error Response: [9] Cloud build [***] status: FAILURE
Error type: UNKNOWN
[...]
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> #php artisan package:discover --ansi
In Compiler.php line 36:
Please provide a valid cache path.
Part of my composer.json:
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi",
"#php artisan vendor:publish --force --tag=livewire:assets --ansi"
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"#php artisan ide-helper:generate",
"#php artisan ide-helper:meta"
],
"post-install-cmd": [
"composer dump-autoload",
"php artisan config:clear",
"php artisan cache:clear",
"php artisan view:clear",
"php artisan cache:clear",
"php artisan optimize:clear"
]
A snippet from app.yaml:
env_variables:
APP_STORAGE: /tmp
VIEW_COMPILED_PATH: /tmp
APP_SERVICES_CACHE: /tmp/services.php
APP_PACKAGES_CACHE: /tmp/packages.php
APP_CONFIG_CACHE: /tmp/config.php
APP_ROUTES_CACHE: /tmp/routes.php
CACHE_DRIVER: database
SESSION_DRIVER: database
I do have /storage/framework/views folder along with the other standard folders under /storage as well as bootstrap/cache.
If I remove this line from composer.json (under "post-autoload-dump"):
"#php artisan vendor:publish --force --tag=livewire:assets --ansi"
I am able to deploy the app but it fails on pages that use Livewire components with the following error:
The /workspace/bootstrap/cache directory must be present and writable. (View: /workspace/resources/views/users/edit.blade.php)
ErrorException
in /workspace/vendor/livewire/livewire/src/LivewireComponentsFinder.php (line 58)
in /workspace/vendor/livewire/livewire/src/CompilerEngine.php -> handleViewException (line 41)
in /workspace/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php -> handleViewException (line 60)
in /workspace/vendor/livewire/livewire/src/LivewireViewCompilerEngine.php -> evaluatePath (line 36)
in /workspace/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php -> evaluatePath (line 61)
in /workspace/vendor/laravel/framework/src/Illuminate/View/View.php -> get (line 139)
This happens even though I added the following line to bootstrap/app.php:
$app->useStoragePath(env('APP_STORAGE', base_path() . '/storage'));
following the guide.
Prior to upgrading Laravel, I had no problems deploying the app on App Engine.
This is a really annoying error. It happened every now and then and I still haven't found a fix. I'm sure that there is something weird happening in Cloud Build, I just don't know what. Anyone have any ideas other that the mentioned above please share.
Edit
I believe the issue lies complied views path as explained here
Now, setting VIEW_COMPILED_PATH to /tmp is necessary for the app to run BUT, the error occurs during build. During build, the compiled views cache path is read not from app.yaml but from the config/view.php or maybe .env where the value usually is realpath(storage_path('framework/views')). Now, that is absolutely fine under normal circumstances. The last piece of the puzzle is gcloud app deploy which will for some reason neglect to deploy empty directories or directories with only .gitignore in them, hence, storage/framework/views will not be deployed and during build the error will occur.
Possible fixes:
Add some random file (other than .gitignore) in 'storage/framework/views' before deploying to make sure the directory is available during build.
Change the default value in config/views to a directory that is present during build.
Any other way to ensure that storage/framework/views is not ignored (present during build) should do.
My working solution was to edit config/view.php:
'compiled' => env(
'VIEW_COMPILED_PATH',
isset($_SERVER['GAE_SERVICE']) ?
'/tmp'
: realpath(storage_path('framework/views'))
),
This will make sure that the default location for compiled views when the app is running on GAE machine is located to /tmp directory instead of storage/framework/views.
The solution was to update the Livewire dependency.
Before:
"livewire/livewire": "^1.1",
After:
"livewire/livewire": "^2.1",
Any version beginning with 2.0 seems to work.

Nova Tool not updating

I'm making a Laravel Nova app. I'm trying to create a Nova Tool to import users.
The tool creates just fine, however when i update the code it does not show.
I've digged a bit into this, and the problem seems to be that the tool in the Vendor folder does not get updated.
When i do npm run dev or npm run prod, the tool files get updated inside the /nova-components/{componentname} folder, and not in the vendor folder, which is getting loaded by Nova.
I'm using Xampp on windows.
Inside my nova service provider:
/**
* Get the tools that should be listed in the Nova sidebar.
*
* #return array
*/
public function tools()
{
return [
new UserImport()
];
}
My composer file:
"require": {
"Vrumona/UserImport": "*"
},
"repositories": [
{
"type": "path",
"url": "./nova"
},
{
"type": "path",
"url": "./nova-components/UserImport"
}
],
How do make sure the Tool gets updated in the composer vendor folder?
I can delete the vendor folder and run composer install, but this is a bit tedious while developping.
Thanks!
It is likely that composer is not symlinking the package but rather mirroring. You can confirm by seeing what the output is when you run composer update -- if you see Mirrored from ... then symlinks are unavailable which will cause the issue that you're seeing.
As you noticed, you can force symlinks in the composer file using:
"options": {
"symlink": true // Will force symlinks
}
And the relevant documentation if needed: https://getcomposer.org/doc/05-repositories.md#path
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan view:clear

Platform independent composer post-install-cmd script

Lets say my project has following structure
project\
templates\
web\assets\
composer.json
When running the composer update by default symlink to my project is created in vendor/ directory. I would like to create a custom post-install-cmd script that would create symlink to templates\ and web\assets\ folder in a different location.
Since my team is working on Windows/Mac/Linux I planned in running a simple php commands to make this happen. I can't seem to figure out where to start ...
The thing is, I can't figure out where is my current location when starting a php script? I've tried creating an empty file to see where it creates it, but it doesn't even create it.
This is what I wish to get working
"scripts": {
"post-install-cmd": [
"php -r \"symlink('/vendor/project/templates', '/templates/project');\"",
"php -r \"symlink('/vendor/project/web/assets', '/web/project/assets');\""
]
}
You should probably remove leading slashes from paths - at least on unix it will be interpreted as absolute path and definitely will not point to your project.
"scripts": {
"post-install-cmd": [
"php -r \"symlink('vendor/project/templates', 'templates/project');\"",
"php -r \"symlink('vendor/project/web/assets', 'web/project/assets');\""
]
}
If you want a bulletproof solution, you should probably create PHP helper class and use __DIR__ lub composer API to define correct paths. See examples in documentation.

Class App\Http\Controllers\Auth\AuthController does not exist

i followed these , laravel virsion 5.4.16
https://www.youtube.com/watch?v=bqkt6eSsRZs&t=29s
You need to regenerate namespaces autoload
composer dump-autoload
"php artisan make:auth" produces all the authentication scaffolding required for the authentication process.
Type "php artisan make:auth" in your terminal right in the directory of your project. You will need to tidy up your install by deleting the "layouts folder" folder within the "resources folder", and also change the "#extends('layouts.app')" to "#extends('main')" in the login.blade.php and register.blade.php views within the "resources/views/auth" folder. Also you should then run "php artisan route:list" to see the names and locations of the auth routes.
I hope this helps

Laravel config subfolder not recognized on new server

I have some config files of US state counties, for example:
config/
state/
alabama/
counties.php
alaska/
counties.php
...
And on my development localhost server, I call them with:
Config::get('state/alabama/counties');
and it works, it loads an array of counties which I display somewhere.
But when I deploy this app on the Heroku, they won't show up.
I was thinking that it maybe has a problem with treating the config/state/subfolder as an environment config?
I do have a config/staging subfolder, in which I have new DB config stuff, and it works with no problem,
but on the Heroku app, the states just won't show up.
Have you added this directory to your autoload mapping in composer.json and then run composer dump-autoload? Without this, Laravel doesn't know to load your new files in to consideration.
Composer is a CLI-run file that exists in the Root of each laravel installation. composer.json is the config file for Composer - it uses this to manage your dependencies.
There's a section in composer.json called "autoload." These are the files that will automatically be loaded each time the app boots. Mine looks like this:
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php",
"app/core"
]
For each folder that didn't exist before and that I wanted Laravel to understand, I added an entry here. Then, I ran composer dump-autoload and Laravel "understood" where the files I wanted to use were.
Each time you add a file, class, repository - anything that you want Laravel to automatically use, you'll have to run composer dump-autoload.
P.S: If composer dump-autoload doesn't work, try composer.phar dump-autoload.

Resources