Nova Tool not updating - laravel

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

Related

Run Laravel Seeder From Package

I'm working on a package for an internal Laravel application and I'm having trouble running a seeder that exists in the package directory.
In my package's composer.json file located in packages/vendor/packagename, I've added the following:
"autoload": {
"psr-4": {
"Vendor\\PackageName\\": "src/",
"Vendor\\PackageName\\Database\\Factories\\": "database/factories/",
"Vendor\\PackageName\\Database\\Seeders\\": "database/seeders/"
}
},
I have the following file located in "packages/vendor/packagename/database/seeders/DepartmentSeeder.php"
<?php
namespace Vendor\PackageName\Database\Seeders;
use Illuminate\Database\Seeder;
use Vendor\PackageName\Models\Department;
class DepartmentSeeder extends Seeder
{
/**
* Run the database seeds.
*
* #return void
*/
public function run()
{
Department::factory()->count(10)->create();
}
}
I then attempt to run the following command:
$ php artisan db:seed --class="Vendor\\PackageName\\Database\\Seeders\\DepartmentSeeder"
Target class [Vendor\PackageName\Database\Seeders\DepartmentSeeder] does not exist.
If I move the seeders directory into my src directory and run the following, it works, but I'd rather keep my seeders in my database directory.
$ php artisan db:seed --class="Vendor\\PackageName\\seeders\\DepartmentSeeder"
Does anyone have any idea why the class isn't being found? All my Google search results are purple and I even went to page two =/
Solution
In my particular case, composer dump-autoload wasn't doing the trick. What I ended up doing was running composer update vendor/packagename and whatever the issue was, it was resolved.
Hopefully, this helps anyone else who may have similar issues.
In my particular case, composer dump-autoload wasn't doing the trick. What I ended up doing was running composer update vendor/packagename and whatever the issue was, it was resolved.
Hopefully, this helps anyone else who may have similar issues.

Laravel Nova tool wouldn't update if symlink is set to true on composer.json

So I am running into a weird issue. I used Laravel Nova (2) command to generate a tool. It sits at ./nova-components/CustomNovaDashboard. In order for the deployment to work on Laravel Vapor, I had to add the below to my parent composer.json.
{
"type": "path",
"url": "./nova-components/CustomNovaDashboard",
"options": {
"symlink": false
}
}
This above allows the code to get deployed, because the absence of symlink in options would otherwise throw the following error:
include(/tmp/vendor/composer/../acme/custom-nova-dashboard/src/ToolServiceProvider.php): failed to open stream: No such file or directory
But the problem now is that when I run npm run watch inside ./nova-components/CustomNovaDashboard, the code in development never updates, because somehow there is a copy of the code that sits in vendor/acme/custom-nova-dashboard that doesn't pick up the changes.
How can I solve this?
I found a solution, it was quite simple.
In my vapor.yml, I had to add COMPOSER_MIRROR_PATH_REPOS=1 before composer install.
build:
- 'COMPOSER_MIRROR_PATH_REPOS=1 composer install'
- 'php artisan event:cache'
- 'npm ci && npm run dev && rm -rf node_modules'
This ensures the symbolic link generated by nova:tool works on dev and prod similarly.
Just don't forget to set "symlink": true in your composer.json. Or leave it as is originally generated by the nova:tool command.

Laravel Spark 11 - edit Spark source files not working anymore

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

Class 'Tests\DuskTestCase' not found in ExampleTest.php

I am trying to run Laravel Dusk tests, but when I run the test, a new Chrome tab pops up with this message.
Fatal error: Class 'Tests\DuskTestCase' not found in path-to-project\tests\Browser\ExampleTest.php on line 9
All I have done so far is run composer require --dev laravel/dusk:^1.0 and php artisan dusk:install.
This is my ExampleTest.php (exactly how Laravel set it up)
<?php
namespace Tests\Browser;
use Laravel\Dusk\Chrome;
use Tests\DuskTestCase;
use Laravel\Dusk\DuskServiceProvider;
class ExampleTest extends DuskTestCase
{
/**
* A basic browser test example.
*
* #return void
*/
public function testBasicExample()
{
$this->browse(function ($browser) {
$browser->visit('/')
->assertSee('Laravel');
});
}
}
DuskTestCase.php is also just as Laravel set it up and has the namespace namespace Tests;.
I am using Laravel 5.4 and Dusk 1.0. I am running the test through PhpStorm, using the work around described here.
Anyone know why DuskTestCase can't seem to be found, even though it appears to be set up correctly? Thanks in advance.
In composer.json:
add "Tests\\": "tests/" in
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Tests\\": "tests/"
}
},
then, run composer dump-autoload to reload your packages.
I had this error due to using out-of-date docs that didn't include this line:
$ php artisan dusk:install
If composer dump-autoload does not solve problem, you can try these steps.
Visit homepage in your browser and check if it renders properly. If not, then you probably have a problem with your webserver configuration (Hint: isn't your project subdirectory of document root?).
You can try Laravel inbuilt server via php artisan serve. If homepage is accessible in your browser now, then you can try dusk again.
In that case, remember to update your .env file to match APP_URL=http://127.0.0.1:8000,
and run php artisan dusk from another cli window, cause php artisan serve needs to be running also.
if you test using a phpstrom then u have set path of phpunit ......
in settings/languages & framework/php/test frameworks and use composer autoloader path and then select a path of your laravel dusk project with autoload.php file.....
set file a vendor/autoload.php file in path to script...

How do I set up Bootstrap after downloading via Composer?

I'm a beginner with Composer, so I know little about it and have little experience with web application development.
I was reading the Nettuts+ Tutorial, and have a basic question about Composer.
{
"require": {
"laravel/framework": "4.0.*",
"way/generators": "dev-master",
"twitter/bootstrap": "dev-master",
"conarwelsh/mustache-l4": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
"mockery/mockery": "0.7.*"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-update-cmd": "php artisan optimize"
},
"minimum-stability": "dev"
}
If I set up my composer.json file as above, after executing composer install --dev, how do I make Bootstrap available for use in the Laravel project?
I mean, I can see the Bootstrap package is downloaded to the vendor directory. Before I only used to download Bootstrap from its official website and manually put the files in the public directory of Laravel, but what is the right way to do this here? Can I leave the Bootstrap files where they are, because I want to update the Bootstrap package to its latest version periodically?
Thanks.
We have artisan command to publish the assets(CSS, JS,..). Something like this should work.
php artisan asset:publish --path="vendor/twitter/bootstrap/bootstrap/css" bootstrap/css
php artisan asset:publish --path="vendor/twitter/bootstrap/bootstrap/js" bootstrap/js
i am not sure about the path.. But this should work.
As the tutorial says, you have to copy it to your public directory:
cp vendor/twitter/bootstrap/docs/assets/js/html5shiv.js public/js/html5shiv.js
cp vendor/twitter/bootstrap/docs/assets/js/bootstrap.min.js public/js/bootstrap.min.js
EDIT:
You really have copy them, because your assets files should lie in the public folder only and Composer is all about putting packages on your vendor's folder, which must not be visible to the outside world.
But you can create a Composer post-install-cmd:
{
"scripts": {
"post-update-cmd": "MyVendor\\MyClass::postUpdate",
}
}
And make it copy those files for you every time an update happens. It can be written using PHP, bash or any other language you can run on your host. Docs: http://getcomposer.org/doc/articles/scripts.md.
Just realised that php artisan asset:publish --path="vendor/twbs/bootstrap/dist/" bootstrapor php artisan vendor:publish --path="vendor/twbs/bootstrap/dist/" bootstrap do not work anymore.
What worked for me is editing the composer.json to add the following under scripts, post-update-cmd:
"scripts": {
"post-update-cmd": [
"php artisan optimize",
"mkdir -p public/bootstrap",
"cp -R vendor/twbs/bootstrap/dist/ public/bootstrap/"
]}
Just symlink the folder like said above by LeviXC:
{
"scripts": {
"post-update-cmd": "ln -sf vendor/twitter/bootstrap/dist/ public/vendor/bootstrap/"
}
}
Or multiple commands:
{
"scripts": {
"post-update-cmd": [
"php artisan optimize",
"ln -sf vendor/twitter/bootstrap/dist/ public/vendor/bootstrap/"
]
},
}
The solution with composer post update script (post-update-cmd) in Windows environment could be:
{
"require": {
"twbs/bootstrap": "4.3.1"
},
"scripts": {
"post-update-cmd": [
"RMDIR public\\assets\\bootstrap /S /Q" ,
"XCOPY /E /I vendor\\twbs\\bootstrap\\dist public\\assets\\bootstrap"
]
}
}
You will have the bootstrap files inside public\assets\bootstrap folder ready to be imported in HTML.
This worked better for me
"scripts": {
"post-update-cmd": [
"mkdir -p html/vendor/",
"ln -sfr vendor/twbs/bootstrap/dist html/vendor/bootstrap"
]
},
The "r" flag made the symlink relative, thus pointing to the real folder
I am new to Laravel and Bootstrap (and to using them together) and I stumbled across this thread when having the same issue. I created a new Laravel project, then added Bootstrap by running the following command from within the root directory of the Laravel project:
%composer require twbs/bootstrap
Then, in my view file, I included the following code:
<link href="css/app.css" rel="stylesheet">
It appears that composer (or bootstrap) adds app.css which includes the Bootstrap css files (which are located in the non-public vendor folder) by reference. Adding the reference to app.css worked, and I was able to use Bootstrap components in my view.

Resources