Laravel run package migration by composer update automatic - laravel-5

I have a package and my ServiceProvider copies the migrations. This works fine after php artisan migrate. But now i want to execute the package migration when i do composer update name/name-package.
So, php artisan update name/packagename and directly automaticly migrate.
How can i achieve that?
$this->publishes([
__DIR__ . '/database/migrations' => $this->app->databasePath() . '/migrations'
], 'migrations');

in application (not package) composer.json
"scripts": {
"post-update-cmd": [
"php artisan optimize",
"php artisan migrate"
]
}
the order of commands is up to you. Also, you may create a command or use php artisan vendor:publish --provider=... to move the migrations

Related

How to create a new migration file under laravel-modules?

reading how laravel-modules works for laravel 6
https://nwidart.com/laravel-modules/v6/advanced-tools/artisan-commands
I did not find how to create a new migration file. I tried 2 ways and failed both :
root#95e2f26acdf8:/app/Modules/Opportunities# php artisan make:migration leads_table_add_test_id_fields --table=leads
Could not open input file: artisan
root#95e2f26acdf8:/app/Modules/Opportunities# php artisan make:migration Opportunities leads_table_add_test_id_fields --table=leads
Could not open input file: artisan
root#95e2f26acdf8:/app/Modules/Opportunities# cd ../
root#95e2f26acdf8:/app/Modules# cd ../
root#95e2f26acdf8:/app# php artisan make:migration Opportunities leads_table_add_test_id_fields --table=leads
Too many arguments, expected arguments "command" "name".
MODIFIED :
Yes, that command
php artisan module:make-migration leads_table_add_test_fields Opportunities
works ok. But I tried to add --table= option as
php artisan module:make-migration leads_table_add_test_fields Opportunities --table=opportunities
but got error :
The "--table" option does not exist.
?
Which way is correct ?
I think you should run:
php artisan module:make-migration add_field_to_leads_table Opportunities

Impossible to create the root directory - swagger with laravel

I'm trying to add swagger documentation on my laravel rest API. First of all, I have installed the composer require "darkaonline/l5-swagger" and then composer require zircote/swagger-php then I have run
php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider"
but the follwuing error occures.
League\Flysystem\Exception : Impossible to create the root directory "".
at C:\xampp\htdocs\landing-temp\vendor\league\flysystem\src\Adapter\Local.php:112
108| clearstatcache(false, $root);
109|
110| if ( ! is_dir($root)) {
111| $errorMessage = isset($mkdirError['message']) ? $mkdirError['message'] : '';
> 112| throw new Exception(sprintf('Impossible to create the root directory "%s". %s', $root, $errorMessage));
113| }
114| }
115| }
116|
Exception trace:
1 League\Flysystem\Adapter\Local::ensureDirectory()
C:\xampp\htdocs\landing-temp\vendor\league\flysystem\src\Adapter\Local.php:78
2 League\Flysystem\Adapter\Local::__construct()
C:\xampp\htdocs\landing-temp\vendor\laravel\framework\src\Illuminate\Foundation\Console\VendorPublishCommand.php:235
Please use the argument -v to see more details.
What should I do to solve this problem?
For Laravel 8. Documentation says that it uses a package auto-discovery feature. But it's not true.
You have to add to your config/app.php in providers section:
L5Swagger\L5SwaggerServiceProvider::class,
Then, you have to run the
php artisan config:cache
And only then, you can run the
php artisan vendor:publish --provider 'L5Swagger\L5SwaggerServiceProvider'
Versions: Laravel 6, darkaonline/l5-swagger : "6."*
Just add this line in your .env file
L5_SWAGGER_GENERATE_ALWAYS=true
Then run this command
php artisan config:cache
At the end run this command
php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider"
This worked for me :)
composer require darkaonline/l5-swagger
For use of #SWG annotation we are going to install the following package,
composer require zircote/swagger-php
and then run this artisan command,
php artisan vendor:publish --provider 'L5Swagger\L5SwaggerServiceProvider'
check your read/write permissions:
https://laravel.com/docs/8.x/installation#directory-permissions
as root:
cd /dir/to/your/laravel-app
chmod -R 750 .
chmod -R 770 ./storage
chmod -R 770 ./bootstrap/cache
And what also worked me after I checked the permissions: php artisan config:cache source or for laravel versions > 7 php artisan optimize

Publishing custom package files using Laravel with composer

I have created new package and i want to avoid publish command separately and i need to include publish command inside package composer.json file. So when package is install it should move the files according to service provider path.
I tried below method but assets/files are not published.
"scripts": {
"post-install-cmd": [
"php artisan vendor:publish --provider=\"<vendorname>\\<packagename>\\<Serviceprovider>\" --tag=public --force",
"php artisan migrate"
],
"post-update-cmd": [
"php artisan vendor:publish --provider=\"<vendorname>\\<packagename>\\<Serviceprovider>\" --tag=public --force",
"php artisan migrate"
]
}
But it works fine when directly run the command like below
php artisan vendor:publish --provider="<vendorname>\<packagename>\<Serviceprovider>"
Please provide solution for it.
Did you try with below code manually. If it returns the thing you need, then you are on the right track. Else some typo is on command of script.
composer run-script post-install-cmd
Composer does not support automatically running scripts other than those at root level. This is somewhat contested, but doesn't look like it's going to change any time soon.
Your best bet is probably to manually run the command / instruct users to manually run the command in your readme: composer run-script post-install-cmd -d ./vendor/[name]/[package]
Maybe you should try to use # before command, and also I suggesting to you to try write command in "post-autoload-dump" section. It is work for me.
"scripts": {
"post-autoload-dump": [
"#php artisan vendor:publish --provider='<vendorname>\\<packagename>\\<Serviceprovider>' --tag=public --force",
"#php artisan migrate"
]
}

Getting messages feature in Debugbar to work in Laravel

I've installed Debugbar for Laravel as described in the steps on the website https://laravel-news.com/laravel-debugbar; and tried to make use of the Messages feature by placing the following below in my code.
Debugbar::info($object);
Debugbar::error('Error!');
Debugbar::warning('Watch out…');
Debugbar::addMessage('Another message', 'mylabel');
But when I run my website, I get the error message from Laravel saying:
1/1
FatalErrorException in HistoryController.php line 11:
Class 'App\Http\Controllers\Debugbar' not found
I have to go like /Debugbar::info(...) or put use Debugbar at the top of my code to not get the error message. Why can't I use it straight like Debugbar::info(...)?
To be able to reference the facade without prefixing it with \ you should add
use Barryvdh\Debugbar;
to the top of your controller.
after adding setting code in /config/app.php
you can use it as a facade
app('debugbar')->info('info message');
or
debugbar()->info('message');
no need use
I think you should try this :
first you add below code in config/app.php
in provider section
'Barryvdh\Debugbar\ServiceProvider',
in aliases section
'Debugbar' => 'Barryvdh\Debugbar\Facade',
after you should clear the cache like:
php artisan config:cache
php artisan cache:clear
php artisan config:clear
Hope this work for you !
Firstly, Go to the terminal and install by typing:-
composer require barryvdh/laravel-debugbar
In second step, Check your laravel verision:-
php artisan --version
In third if your laravel version is greater than 5(Laravel 5.x)
add the ServiceProvider to the providers array in config/app.php
Barryvdh\Debugbar\ServiceProvider::class,
add this to your facades in app.php:
'Debugbar' => Barryvdh\Debugbar\Facade::class,
Finally, published vendor configuration by command:-
php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"
After vendor published clear cache,route,view by command
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan dump-autoload -o

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

Resources