How To Create Package ?
-
- HelloWorldServiceProvider.php file
<?php namespace ACME\HelloWorld\Providers; use Event; use Illuminate\Support\ServiceProvider; /** * HelloWorld service provider * * @author Jane Doe <[email protected]> * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ class HelloWorldServiceProvider extends ServiceProvider { /** * Bootstrap services. * * @return void */ public function boot() { $this->loadRoutesFrom(__DIR__ . '/../Http/routes.php'); $this->loadTranslationsFrom(__DIR__.'/../Resources/lang', 'helloworld'); $this->loadViewsFrom(__DIR__.'/../Resources/views', 'helloworld'); Event::listen('bagisto.admin.layout.head', function($viewRenderEventManager) { $viewRenderEventManager->addTemplate('helloworld::helloworld.layouts.style'); }); $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); } /** * Register services. * * @return void */ public function register() { // $this->mergeConfigFrom( // dirname(__DIR__) . '/Config/menu.php', 'menu.admin' // ); } }
- helloworld.blade.php file -
{{ __('helloworld::app.hello-world.name') }} {{-- @extends('admin::layouts.master') --}}
- routes.php file
<?php Route::view('/hello-world', 'helloworld::helloworld.helloworld');
- app.php file for en.
<?php return [ 'hello-world' => [ 'name' => 'My Name is jane doe', ] ];
Thanks
-
i did these changes but i still can't access that url i think there is an error somewhere else here is my whole project: https://we.tl/t-ZxQA9ugf6s
-
I am unable to open your file but i think you are missing these things -
- Add this to app.php file (Inside Config folder ).
ACME\HelloWorld\Providers\HelloWorldServiceProvider::class
- Add this to composer.json under 'psr-4'.
"ACME\\HelloWorld\\": "packages/ACME/HelloWorld/src"
Run 'php artisan config:clear', 'composer dump-autoload' & 'php artisan vendor:publish'.
and please see attached image for where your package should be -
Thanks
-
This post is deleted! -
thanks a lot i did all those edits in my project then php artisan config:clear , composer dump-autoload , php artisan route:cache and it worked.The problem now is when i go to hello-world i get this displayed "helloworld::app.hello-world.name"
-
You need to add language for this.
<?php return [ 'hello-world' => [ 'name' => 'My Name is jane doe', ] ];
in app.php file for en.
Thanks
-
@rahul thanks a lot it worked !!
-
Hi
is it possible to get a copy as I have the same problem with at package, so a 'base', working example would be great
Thanks
-
Hi @rabol
We don't have any copy of this but you can mentioned your error or any problem that you are facing, we will solve it.
Thanks
-
Hi
May I suggest that you create a 'bolier-plate' for a new package and put it on github, I'm sure that it would help a lot.
Thanks