How to change Laravel Jetstream components path - laravel

I wanna change default Jetstream components after publishing views (php artisan vendor:publish --tag=jetstream-views) from resources/views/vendor/jetstream/components for example to resources/views/path/to/jet/comps

You can do this by copying the components from laravel/jetstream and putting them wherever you like within your app.
Then you need to alias the jetstream class with your own version.
What I did was copy all components from
/vendor/laravel/jetstream/src/Http/livewire/
Copied them to
/app/Http/Livewire/
Then open your app/Providers/JetstreamSrviceProvider.php or if you would prefer you can create your own service provider or use AppServiceProvider.php.
Add the following before the class definition but after the namespace definition:
use Illuminate\Foundation\AliasLoader;
Then in the register method add this:
$loader = AliasLoader::getInstance();
$loader->alias('Laravel\Jetstream\Http\Livewire\ApiTokenManager', 'App\Http\Livewire\ApiTokenManager');
$loader->alias('Laravel\Jetstream\Http\Livewire\CreateTeamForm', 'App\Http\Livewire\CreateTeamForm');
$loader->alias('Laravel\Jetstream\Http\Livewire\DeleteTeamForm', 'App\Http\Livewire\DeleteTeamForm');
$loader->alias('Laravel\Jetstream\Http\Livewire\DeleteUserForm', 'App\Http\Livewire\DeleteUserForm');
$loader->alias('Laravel\Jetstream\Http\Livewire\LogoutOtherBrowserSessionsForm', 'App\Http\Livewire\LogoutOtherBrowserSessionsForm');
$loader->alias('Laravel\Jetstream\Http\Livewire\NavigationDropdown', 'App\Http\Livewire\NavigationDropdown');
$loader->alias('Laravel\Jetstream\Http\Livewire\TeamMemberManager', 'App\Http\Livewire\TeamMemberManager');
$loader->alias('Laravel\Jetstream\Http\Livewire\TwoFactorAuthenticationForm', 'App\Http\Livewire\TwoFactorAuthenticationForm');
$loader->alias('Laravel\Jetstream\Http\Livewire\UpdatePasswordForm', 'App\Http\Livewire\UpdatePasswordForm');
$loader->alias('Laravel\Jetstream\Http\Livewire\UpdateProfileInformationForm', 'App\Http\Livewire\UpdateProfileInformationForm');
$loader->alias('Laravel\Jetstream\Http\Livewire\UpdateTeamNameForm', 'App\Http\Livewire\UpdateTeamNameForm');
Then run
composer dump-autoload
You can then open your version of the components and modify the view paths if you prefer or whatever else it is you were looking to do.
I have built a CMS as a package and done exactly this from a package which works well and means we can ship the package with our own views and updated components.

Related

Need install Laravel-ide-helper for VS Code

I use VS Code, not use PHP Storm. Should I install 'laravel-ide-helper'?
You can require this package with composer using the following command:
composer require --dev barryvdh/laravel-ide-helper
Then if you are using Laravel versions older than 5.5, add the service provider to the providers array in config/app.php:
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class
In Laravel, instead of adding the service provider in the config/app.php file, you can add the following code to your app/Providers/AppServiceProvider.php file, within the register() method:
public function register(){
if ($this->app->environment() !== 'production') {
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
// ...
}
This basically allow your application to load the Laravel IDE Helper on non-production environments.
It does help with code completion (automatically importing classes, showing methods, etc..). It works with VSCode the same as it does for PHPStorm as far as I can tell. The 'ide-helper-models' also appears to work the same. I'm unsure what the 'ide-helper:meta' does, but the docs only mention support for PHPStorm.

OctoberCMS and BotMan

I want to integrate a chatbot (BotMan version 2.0) into an existing OctoberCMS project , here is what I did till now :
1- I added BotMan to the projct using the following command :
composer require botman/botman
2- I created a routes.php file in the same directory as the plugin.php file
<?php
use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
//Route::match(['get', 'post'], '/botman', 'BotManController#handle');
//Route::get('/botman/tinker', 'October\Demo\BotManController#tinker');
// Create an instance
$botman = BotManFactory::create($config);
// Give the bot something to listen for.
$botman->hears('hello', function (BotMan $bot) {
$bot->reply('Hello yourself.');
});
// Start listening
$botman->listen();
My questions are :
1- Where I have to add the BotManController.php file
2- I tried to add BotManController.php in the same directory as the routes.php file but I get the following error :
Class 'App\Http\Controllers\Controller' not found
( and thats because its an OctoberCMS project not Laravel project ... I dont have the App directory )
Can anyone please provide me a solution to that or another way to integrate Botman into OctoberCMS !
First off, read https://luketowers.ca/blog/how-to-use-laravel-packages-in-october-cms-plugins/ as well as https://octobercms.com/docs/plugin/composer.
Secondly, you can put the BotManController file anywhere in your plugin you want as long as you understand PHP namespaces and how to properly reference it where you want to. I would probably recommend putting it in a /classes/ directory under your plugin folder, and then changing the App\Http\Controllers\Controller reference to instead reference the base Illuminate\Routing\Controller class. You could also put it in a /controllers/ directory, but in OctoberCMS that is typically reserved for your backend controllers so I wouldn't recommend mixing the two.

Hot to use emcconville/google-map-polyline-encoding-tool in laravel

Hi i have installed emcconville/google-map-polyline-encoding-tool in Laravel, with composer, but cant see any references to the extension when i try yo use it in a class.
Do i need to register the extension anywhere in Laravel?
You don't need to register the package as an extension, the class Polyline coming from the package is automatically loaded with PHP/Composer autoload mechanism, so you can use it directly in your code (as per docs):
$points = array(
array(41.89084,-87.62386),
array(41.89086,-87.62279),
array(41.89028,-87.62277),
array(41.89028,-87.62385),
array(41.89084,-87.62386)
);
$encoded = \Polyline::encode($points);

Dynamic redirect in package route

I have defined a route action with some business logic, inside an internally developed package. Depending on the result in this action, the app want to redirect the user to some dynamic route (Redirect::route('admin.index', [$app->id]) e.g).
How would I do this?
Any solution I come up with doesn't work because of the way Laravel handles routes.
Right now I have copied the route to the app routes.php, and extracted the business logic to a method inside the package. But this is not optimal, as I'd like to also keep the route inside the package.
Laravel has some documentation on Package Configuration that should work for you.
In your package's src/config/config.php:
<?php
return array(
'route_admin_index' => 'admin.index',
);
Change your package's code to:
Redirect::route(Config::get('your_package_name::route_admin_index'), [$app->id]);
Now when installed on different environments, you can do:
php artisan config:publish your_vendor_name/your_package_name
Which will publish your package's configuration file to:
app/config/packages/your_vendor_name/your_package_name
Where then you can change the route_admin_index at will.
If php artisan config:publish was not called. Your route will default back to what you have in your package's config file.

Laravel 4 class not found error

I'm getting an error that a class (a controller) is not being found. Thing is, it is found in my local development environment. I created the controller with php artisan controller:make CssController --path=app/controllers/home.
I renamed the class (not the file) Home_CssController. I added the route:
Route::get('home/css-php', 'Home_CssController#index');
to my routes file. Everything works fine in my local environment. I did forget to run composer dump-autoload but there were no issues with viewing the controller/view in my local environment. I've uploaded everything to the live server, but I'm getting the error:
Class Home_CssController does not exist
I've uploaded the controller, the routes file and the view multiple times. But I still get the error. Is it because the controller wasn't registered with composer? I've since registered it, but am not sure what I need to upload to the server. I've uploaded both the config and bootstrap folders. What do I need to do to get the controller/view to be found? This is Laravel 4.
If the controller isn't in the app/controllers folder, then it will need to be namespaced (unless you want to continue using your autoload.php trick).
Namespace Home_CssController to Home.
<?php namespace Home;
class CssController extends \BaseController
Then, you can use it in your routes:
Route::get('home/css-php', 'Home\CssController#index');

Resources