OctoberCMS and BotMan - laravel

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.

Related

How to change Laravel Jetstream components path

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.

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);

location of helper function in Laravel 5

I am using Laravel 5 and new in this Platform. I studied about URL:asset In the earlier version of PHP, we could find the helper function in Auto Load or config files.
Do the helper function list exists somewhere in the Framework directory where if we want to change something in the helper function according to our need.
The helper functions are present in
/vendor/laravel/framework/source/illuminate/Foundation/helpers.php
You can find your helper function inside app.php as facades are registered on app.php and service container would let you resolve the class anywhere you want by use shorthandname or registered name;

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 - changing resource root routing path

In a Laravel 4 installation, Using Jeffrey Way's Laravel 4 Generators, I set up a 'tweet' resource, using the scaffolding command from his example:
php artisan generate:scaffold tweet --fields="author:string, body:text"
This generated the model, view, controller, migration and routing information for the tweet type. After migrating the database, visiting http://localhost:8000/tweets works fine, and shows the expected content.
The contents of the routes.php file at this point is:
Route::resource('tweets', 'TweetsController');
Now I would like to move the url for tweets up one level into admin/tweets, so the above url should become: http://localhost:8000/admin/tweets. Please note that I am not treating 'Admin' as a resource, but instead just want to add it for hypothetical organizational purposes.
Changing the routes.php file to:
Route::resource('admin/tweets', 'TweetsController');
Does not work, and displays the following error:
Unable to generate a URL for the named route "tweets.create" as such route does not exist.
Similarly when using the following:
Route::group(array('prefix' => 'admin'), function() {
Route::resource('tweets', 'TweetsController');
});
As was suggested in this stackoverflow question.
Using php artisan routes reveals that the named routes also now have admin prefixed to them, turning tweets.create into admin.tweets.create.
Why is the error saying that it cannot find tweets.create? shouldn't that automatically be resolved (judging by the routes table), to use admin.tweets.create?
How can I change my routing so that this error no longer occurs?
I just tested with new resource controller and it works fine for me.
The problem is not with the Route, its with the named routes used in your application.
check your view files there are link to route like link_to_route('tweets.create', 'Add new tweet'), this is creating the error because when you add admin as prefix tweets.create doesn't exists so change it to admin.tweets.create every where, in your controller also where ever named route is used.

Resources