Create own laravel package - laravel

I try to create own laravel package.
I created package folder in my project in root directory.
Than created simplexi/greetr/src folders in package.
I added to autoload "Simplexi\Greetr\": "package/simplexi/greetr/src" in composer.json in main project, and used command composer dump-autoload.
Than in src folder I created RiakServiceProvider, added this provider to config=>app.php to providers array.
Then in boot method I added next code:
$this->publishes([__DIR__ . '../config/myconf.php' => config_path() . '/']);
And executed next command:
php artisan vendor:publish --provider="\Simplexi\Greetr\RiakServiceProvider"
Than I got Publishing complete.
But file myconf.php didn't copy to app/config.
Also I checked file myconf.php in my package/simplexi/greetr/config folder and it exists.
Can anyone tell me what the problem might be?

publishes() expect two parameters. Try something like this:
$this->publishes([
__DIR__.'/../config/myconf.php' => config_path('myconf.php'),
], 'config');

Related

after Update laravel 6.2 [App\Http\Controllers\Auth\ConfirmPasswordController] does not exist

I update laravel from v 6.0 to v6.2 and after the finish, I try php artisan route:list
This error
I had the same issue, i fixed it with the following solution:
Create a empty file named "ConfirmPasswordController.php" in the folder App/Http/Controllers/Auth
Go to https://github.com/laravel/laravel/tree/master/app/Http/Controllers/Auth en open the file named "ConfirmPasswordController.php"
Copy all the file contents to your newly created file and save it.
This should fix the error.
Edit
The problem is, were updating the composer dependencies, but not the core application. But de composer dependencies expect you to update the core. They refer to files on the core application that not exists (because the application is not up-to-date).
See: How to update Laravel Application (not the composer dependencies)
This has been fixed. Just update to Laravel 6.4
Step1. Create ConfirmPasswordController.php file in app/Http/Controllers/Auth/ path.
Step2. ConfirmPasswordController.php paste this content to ConfirmPasswordController.php file.
From v6.0.0 to v6.2.0 the following addition and modifications were made.
Added app/Http/Controllers/Auth/ConfirmPasswordController.php
Modified app/Http/Controllers/Auth/ForgotPasswordController.php
Modified app/Http/Controllers/Auth/ResetPasswordController.php
Modified app/Http/Kernel.php
Modified config/auth.php
Modified resources/lang/en/validation.php
You can see the diff of v6.0.0 to v6.2.0 here.
Create ConfirmPasswordController.php manually and It's may be duplicate of - duplicate
1 ) Open file vender/laravel/framework/src/Illuminate/Routing/Router.php".
2 ) and comment these
// $this->get('password/confirm', 'Auth\ConfirmPasswordController#showConfirmForm')->name('password.confirm');
// $this->post('password/confirm', 'Auth\ConfirmPasswordController#confirm');

After rename app folder and namespace artisan make shows Exception: Unable to detect application namespace

I've renamed my app folder to aplicativo and changed the namespace to aplicativo. Everything works but artisan make commands.
I changed namespace through composer.json
"psr-4": {
"aplicativo\\": "aplicativo/",
}
Plus command:
artisan app:name aplicativo
You won't get this to work. You can rename the namespace (as you did with the command), but you can't rename the directory because it's hardcoded as app.
You can see the source here.
Then... if your using composer try this command
composer dump-autoload
The good news is that Laravel has now added support for custom App path. You can override the App path by adding the following code in bootstrap/app.php (or provider).
/*...*/
$app = new Illuminate\Foundation\Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);
// override the app path since we move the app folder to somewhere else
$app->useAppPath($app->basePath('src'));
Similarly, you can change other paths (database, language, storage, etc.). You can find all the available methods here.

View [layouts.app] not found in laravel

I have created an application in laravel using appzcoder crud-generator plug-in. i have done everything accordingly but i am getting the above mentioned error. I have a folder named layouts in views folder and this folder has app.stub in it. but when i run the project it gives the following error
View [layouts.app] not found. (View:C:\wamp64\www\myProject\resources\views\admin\items\index.blade.php)
make sure you have run below code if not run it will create layout.app path
or manually create view/layout/app.php
php artisan vendor:publish --provider="Appzcoder\CrudGenerator\CrudGeneratorServiceProvider"

Laravel 5.1 rename project

What is the best solution if I want to rename my laravel 5.1 project, I just tried to rename one but it did not work properly got some errors.
Are there some kind of steps one has to do to rename a laravel project?
You should use php artisan app:name command to rename your app. It will change namespace in all project files for you. This is the only right way to rename your app.
https://laravel.com/docs/5.0/configuration#after-installation
From laravel version 5.3^ there is a function to call the app name
config('app.name');
You can change the default name 'Laravel' inside this file
config/app.php
'name' => 'Laravel',
And also inside .env file
APP_NAME=Laravel
I just recommend to:
go to .env file at APP-NAME =
put your desired name in "" (double quotes)
restart your server
And you're done.
You can change your project name using the following command:
php artisan app:name your_git_name\your_app_name

How can I push my package's assets into root directory?

I have a package with some assets.
vendor/package/src/assets/css|js|img etc.
How can I move those assets into root directory after installation or updating?
Also, the second question is, can I do this task with PHP? For example:
Route::get('update/{package_name}', function() {
//Trigger composer here
});
Thank you.
there is an artisan command for that
php artisan asset:publish vendor/package
for this to properly work, you'd need to put your assets into a public folder within your vendor package like vendor/package/public/(css|js|img|...) and everything will be published to your root under public/packages/vendor/package/(css|js|img|...).
you can specify a path from the root, if you're not using the public folder:
php artisan asset:publish vendor/package --path="vendor/vendorname/package/src/assets"
docs: http://laravel.com/docs/packages#package-assets (although the path parameter is not mentioned there)
I think what he wants is a different destination folder not the source folder. --path is useful when you have a different source folder I believe.

Resources