I moved the User.php in my laravel installation to a different folder and adjusted the namespace accordingly. Still, when I login into the page, laravel is not able to find the class and throws an error.
I ran composer clear-cash and composer dump-autoload but still it is not working as Laravel still searches for App/User.php instead of App/Classes/User/User.php
The User.php looks like this:
namespace App\Classes\User;
use App\Events\EventGenerator;
use App\Events\User\UserRegistered;
use App\Permission;
use App\Role;
use Laratrust\Traits\LaratrustUserTrait;
use \Illuminate\Contracts\Auth\Authenticatable as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Console\Command;
class User extends Model implements Authenticatable {
use EventGenerator;
(...)
You need to change the class the path in auth.php
In your auth.php
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Classes\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
Idea is to change the path of 'model' => App\Classes\User::class, to your class.
Hope this helps
There is a reference to the user model in auth config, you'll probably need to adjust the namespace there.
File: config/auth.php
Setting: providers -> users -> model
Related
I am trying to use the standard Laravel auth related functionality. I have the standard login, register, logout, etc... working fine. But my problem is that whenever I go to use functions like Auth::user() this is returning the GenericUser model rather than my own App/Models/User.php model. The problem is that my User's model has some foreign key references to other data so I would like to work exclusively with my User model.
For example, when trying to make a Policy I am running into an error:
Argument 1 passed to App\Policies\ContractPolicy::before() must be an
instance of App\Models\User, instance of Illuminate\Auth\GenericUser
given
And the code simply looks like this:
<?php
namespace App\Policies;
use App\Models\Contract;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class ContractPolicy
{
use HandlesAuthorization;
public function before(User $user, $ability)
{
if ($user->isSuperAdmin()) {
return true;
}
}
public function viewAny(User $user)
{
return $user->isMember();
}
}
The GenericUser model is indeed returning the data from the users table, but the problem is that it is completely different from what my User model gives, and thus includes nothing like the foreign key references or functions I added. I was under the impression that I could switch the model used by switching the config/auth.php provider. Which I did and nothing seemed to change:
'providers' => [
'users' => [
'model' => App\Models\User::class,
],
'users' => [
'driver' => 'database',
'table' => 'users',
],
],
What am I doing wrong here?
You are defining the users provider to use the 'database' driver:
'users' => [
'driver' => 'database',
'table' => 'users',
],
Adjust that to use the 'eloquent' driver instead:
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
The 'database' driver uses Query Builder to interact with the database table and returns an object of GenericUser to represent the currently authenticated user.
The 'eloquent' driver uses an Eloquent Model to interact with the database and returns a Model instance. If you like relationships and all the other features of Eloquent then you should stick with using the 'eloquent' driver. Also, you have defined your Policy methods to be expecting a particular Model passed to its methods.
I'm on a Laravel 5.2 based project, I've to connect it with a DB2 database hosted on an IBM i-series server, I've tried some plugins but this one seems to correspond to my needs :
https://github.com/bencarter78/odbc
I followed the installation steps, filled the database.php file, created a model and a controller but the page keeps returning :
PDOException in Connector.php line 55: invalid data source name
There is my controller :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Illuminate\Support\Facades\DB;
use App\didactp1;
class didactitiel extends Controller
{
public function recupererDidactitiels()
{
$didactitiels = didactp1::all();
return view('didactitiel')->with('didactitiels', $didactitiels);
}
}
My model :
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class didactp1 extends Model
{
protected $connection = 'odbc';
}
But I think the problem comes from the database.php file configuration but I can't find what's wrong :
'odbc' => [
'driver' => 'odbc',
'dsn' => 'AS400',
'host' => 'TheIpOfTheHostingServer',
'database' => 'myDatabaseName',
'username' => 'com11',
'password' => 'pcs400',
],
I tried to connect to the database manually with unixODBC :
error log
odbc.ini
I also tried the $sudo iptables -L command
iptables
Hope that's clear enought, every kind of help is welcome
I am using Nova just as the backend for a SAAS application so basically going to app.mydoain.com just pops up the Nova login form. I want Laravel 5.7 Email Verification that comes standard in use for this (so when I add a user they have to verify the email before the can login).
In config/nova.php I added the middleware:
'middleware' => [
'verified',
'web',
Authenticate::class,
DispatchServingNovaEvent::class,
BootTools::class,
Authorize::class,
],
In User.php model I implemented it (which is done differently than there webiste docs?)
<?php
namespace App;
use Illuminate\Auth\MustVerifyEmail;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Contracts\Auth\MustVerifyEmail as MustVerifyEmailContract;
class User extends Authenticatable implements MustVerifyEmailContract
{
use MustVerifyEmail, Notifiable;
....
I added some routes in web.php for just verification (dont need any other auth)
Route::get('email/verify', 'Auth\VerificationController#show')->name('verification.notice');
Route::get('email/verify/{id}', 'Auth\VerificationController#verify')->name('verification.verify');
Route::get('email/resend', 'Auth\VerificationController#resend')->name('verification.resend');
After I login it just stalls out and either goes to /email/verify or /. In my db I have already added a timestamp so it shouldn't go to /email/verify at all and when it goes to / it times-out.
If i remove verified from the middleware in the config it works fine, but no email verification check.
Change the order of the middlewares.
'middleware' => [
'web',
Authenticate::class,
'verified',
DispatchServingNovaEvent::class,
BootTools::class,
Authorize::class,
],
Your request must go through web first. Most likely you are getting the timeout because of a redirect loop.
I'm kinda a newbie in Cakephp (3.5) and I'm currently trying to make my first plugin (called Example) which contains several sub-directories. One of them is the UserManager directory which contains a Users MVC standard suit with authentication.
Since I want to add social logins and other stuffs, I created my own auth component as explained in the docs :
plugins/Example/UserManager/src/Controller/AppController.php
<?php
namespace Example\UserManager\Controller;
use App\Controller\AppController as BaseController;
class AppController extends BaseController
{
public function initialize()
{
parent::initialize();
$this->loadComponent('Auth', [
'authenticate' => [
'Example/UserManager.Example' => [
'fields' => ['username' => 'email', 'password' => 'pass'],
'userModel' => 'Users',
],
],
]);
}
}
plugins/Example/UserManager/src/Auth/ExampleAuthenticate.php
<?php
namespace App\Auth;
use Cake\Auth\BaseAuthenticate;
use Cake\Http\ServerRequest;
use Cake\Http\Response;
class ExampleAuthenticate extends BaseAuthenticate
{
// The same as Form authentication, since I'm testing
}
The problem is that I can't make the authentication component find the ExampleAuthenticate class. I already tried by setting the authenticate config param like
Example
ExampleAuthenticate
UserManager.Example
Example/UserManager.Example
Example\UserManager.Example
Example/UserManager.ExampleAuthenticate
Example\UserManager.ExampleAuthenticate
but I always get the error Authentication adapter "..." was not found. when visiting http://localhost/Project/example/user-manager/users :(
Does anyone have any clue of what I might be missing?
The problem was that the php function class_exists(...) didn't recognise the custom authentication class, so after digging a bit more I realised that the namespace shown in the docs only works for a custom authentication file defined in the App environment, but not in the Plugin one (silly me).
So I changed namespace App\Auth; to namespace Example\UserManager\Auth; inside ExampleAuthenticate.php and it worked like a charm! now the function class_exists('Example\\UserManager\\Auth\\ExampleAuthenticate') returns true and everything works perfect by defining Example/UserManager.Example in the authenticate config params.
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Paypal;
use Redirect;
use Illuminate\Http\Request;
class SubscriptionController extends Controller
{
private $_apiContext;
public function __construct() {
$this->_apiContext = PayPal::ApiContext(
config('services.paypal.client_id'),
config('services.paypal.secret'));
$this->_apiContext->setConfig(array(
'mode' => 'sandbox',
'service.EndPoint' => 'https://api.sandbox.paypal.com',
'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => true,
'log.FileName' => storage_path('logs/paypal.log'),
'log.LogLevel' => 'FINE'
));
}
I'm getting an error that
Class 'Paypal' not found
in SubscriptionController.php line 17
But my IDE shows that it's there, I even used it in another project and its working fine.
In my app.php I have:
'Paypal' => 'Netshell\Paypal\Facades\Paypal',
So it should be good.
Why do I get that error?
Run this command in your Laravel project root to install Paypal composer require netshell/paypal dev-master
After that, add the service provider to app/config/app.php in the providers array.
'providers' => [
// ...
'Netshell\Paypal\PaypalServiceProvider',
]
At the end, add an alias to app/config/app.php in the aliases array
'aliases' => [
// ...
'Paypal' => 'Netshell\Paypal\Facades\Paypal',
]
After that you should be able to use Paypal
Hope it helps
Try getting rid of the use Paypal; line. If you are defining an alias in app.php, I don't think you need a use statement for it - that has been my experience when defining my own aliases.
You can also try defining your alias with a different syntax to see if it helps:
'Paypal' => Netshell\Paypal\Facades\Paypal::class
(notice there are no quotes on the value as it is a reference to a class).
php artisan config:cache fixed it.
Have you tried doing use \Paypal;?