Class 'App\Http\Controllers\Saml2' not found - php

I'm on Laravel 5, I'm trying to integrate SAML 2.0 with it. I've found this package = https://github.com/aacotroneo/laravel-saml2
I tried follow their steps, but at the end when I use
<?php
namespace App\Http\Controllers;
class SAMLController extends Controller {
public function adminSignIn(){
return Saml2::login(URL::full());
}
}
I've already added
provider
'Aacotroneo\Saml2\Saml2ServiceProvider',
aliases
'Saml2' => 'Aacotroneo\Saml2\Facades\Saml2Auth',
Why do I still get this error?
Class 'App\Http\Controllers\Saml2' not found
Note : I've even retry after sudo composer dumpauto, same result.

You need to use full namespace for the facade:
\Saml2::login(URL::full());
Or add this to the top of the class:
use Saml2;

you need to explicitly write "use" on top
use Saml2;
This might work.

Related

Required "token" not supplied in config and could not find fallback environment variable "TELEGRAM_BOT_TOKEN"

I am using PHP 7.4.1 and Laravel Framework 6.20.16.
I am trying to implement the following library: telegram-bot-sdk and the following version "irazasyed/telegram-bot-sdk": "^2.0",
After installing the sdk and getting my private token from telegram's #botfather. I am trying to use the sdk.
I created a route and a controller:
route
Route::get('telegramHello', 'TelegramController#getHello');
controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Telegram\Bot\Api as Telegram;
use App\Helpers\TelegramResponse as Response;
class TelegramController extends Controller
{
public function getHello() {
$api = new Telegram(); // ----> HERE I GET THE ERROR
$response = $api->getMe();
return Response::handleResponse($response);
}
//...
When opening my route I get the following exception:
The thing I do not understand is that I have created the config telegram.php and loading my correct token from my .env file:
In my .env file it looks like the following:
Any suggestions what I am doing wrong?
I appreciate your replies!
Use Facade, not original API class. Your config is correct, you just using wrong class.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Telegram\Bot\Laravel\Facades\Telegram;
use App\Helpers\TelegramResponse as Response;
class TelegramController extends Controller
{
public function getHello() {
$response = Telegram::getMe();
return Response::handleResponse($response);
}
//...
Also i may recommend you using westacks/telebot instead of irazasyed/telegram-bot-sdk. I created it as irazasyed's was poorly documented and really buggy at a lot of places.
The two comments above helped me the most:
Use "" for your TELEGRAM_BOT_TOKEN
Instead of using your own named .env variable use TELEGRAM_BOT_TOKEN
I hope this works also for others that have this problem.

new laravel package not recognized

I was writing my first laravel package, so I could use it and understand how packages work and learn how to write packages and etc.
But my project didn't recognize the package that I wrote.
Here is my package Github link: https://github.com/IIIphr/Shamsi_Calendar
And this is my main project: https://github.com/IIIphr/aimeos_shamsi
I use this command to add my package to the app: composer require iiiphr/shamsi_calendar
And it'll be added successfully (at least I guess). Then in the temp Controller, I wrote this:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use iiiphr\shamsi_calendar;
class temp extends Controller
{
public function index(){
return shamsi_calendar::get_date();
}
}
And a route:
Route::get('/date','temp#index');
But in the http://localhost:8000/date, I will face this error:
Before, I have tried other ways and the result was anything but success.
Another thing, I have this error in visual studio code in the temp controller:
Undefined type 'iiiphr\shamsi_calendar'.intelephense(1009)
I will appreciate any kind of help :)
You import the library perfectly but you don't use the Calendar Controller that the package gives you. The package haves a controller called CalendarController, you have two ways, extends from this controller or create an instance of this controller, if you extend the controller from this:
<?php
namespace App\Http\Controllers;
use iiiphr\shamsi_calendar\CalendarController;
class temp extends CalendarController
{
public function index(){
return $this->get_date();
}
}
What do you think about it?

How to use Laravels spatie/laravel analytics package

I just downloaded this package for Laravel.
spatie/laravel-analytics
Its a Google Anayltics package, and I followed all the steps for setting up an account. What I'm having trouble is calling the methods. For example when it says:
Here is an example to retrieve visitors and pageview data for the current day and the last seven days.
$analyticsData = Analytics::fetchVisitorsAndPageViews(Period::days(7));
I tried doing this in my function like this:
<?php
namespace App\Http\Controllers\Admin;
use Carbon\Carbon;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Spatie\Analytics\Analytics;
use Illuminate\Support\Collection;
class DashboardController extends Controller {
public function index() {
$analytics = Analytics::fetchVisitorsAndPageViews(Period::days(7));
dd($analytics);
return view('admin.dashboard-v2');
}
}
Its giving me errors like:
Non-static method Spatie\Analytics\Analytics::fetchVisitorsAndPageViews() should not be called statically
Am I missing something here? I couldn't find any specific documentation online except for the Github ReadMe file
If you want to use the facade to access the class, you'll need to change use Spatie\Analytics\Analytics; to use Analytics;. That should take care of that error.
If you are going to use Period::days(7) then you will need to add use Spatie\Analytics\Period; because that's an actual static method, not a facade.

How do I access this in Laravel 5.2?

I'm using Laravel 5.2 and I've followed the instructions stated here.
However, when I attempt to access it in my controller, I get an error:
Class 'App\Http\Controllers\IPBWI' not found # line 12
<?php
namespace App\Http\Controllers;
use Haslv\Ipbwi;
MyController extends Controller {
public function index() {
$member_info = IPBWI::member()->info(); //line 12
//etc
}
}
I understand what's wrong but I don't understand how do to correctly reference it.
Could you help me out?
I'm not sure where you got this, but I would take it out:
use Haslv\Ipbwi;
If you want to use Laravel's facade and you followed the instructions on the github page, then you should add this to the top of your controller:
use IPBWI;
This is also case-sensitive so make sure that it matches the case in this line of code in your config/app.php file:
'IPBWI' => 'Haslv\Ipbwi\Facade',
You need to move your namespace and use statement above the class declaration.
<?php
namespace App\Http\Controllers;
use Haslv\Ipbwi;
class MyController extends Controller {
// controller code
}

Class not found, Laravel Observer

I'm in the process of switching from Laravel 4.2 to Laravel 5, not sure if that is relevant, but I am getting an error:
"Class 'library\observers\UserObserver' not found"
and I have no Idea what the problem is, as far as I can see ( through my frustration mind you ) is that everything is in its right place, name spaces, folders, class names etc.. and I've ran the artisan dump autoload command twice now. the class is an observer which modifies user input on save. here is my code:
UserObserverServiceProvider.php:
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use library\observers\UserObserver;
use App\Models\User;
class UserObserverServiceProvider extends ServiceProvider
{
public function boot()
{
User::observe( new UserObserver );
}
public function register(){}
}
UserObserver.php:
<?php namespace library\observers;
use library\Facades\Geo;
use Geocode;
use State;
use City;
class UserObserver{ code for user observer }
app.php configuration for service provider:
'App\providers\UserObserverServiceProvider',
All of these things were working together before the switch, what am I missing?
I left the App out of the namespace and path for use, works now, thanks!

Categories