[![This is the error][1]][1]
This is the Controller.php but i think this is a built in when creating a laravel project.
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
In my LoginController under Auth, I have used the following codes:
namespace App\Http\Controllers\Auth;
use App\Model\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Redirect;
use Hash;
use Auth;
use DB;
use App\Model\UserAdmin;
class LoginController extends Controller {
use AuthenticatesUsers;
public function __construct() {
$this->middleware('guest')->except('logout');
}
public function doLogin(Request $request) {
$userdata = array(
'email' => Input::get('email'),
'password' => Input::get('password'),
'status' => '1',
);
if (Auth::guard('admin')->attempt($userdata)) {
return Redirect::intended('/administrator/dashboard')->with('successMessage', 'You have successfully logged in.');
}
}
}
And in UserAdmin (model) under app/Model is as follows:
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Config;
class UserAdmin extends Authenticatable {
protected $table = 'adminusers';
public $timestamps = false;
protected $fillable = ['firstName', 'lastName', 'email', 'company', 'website'];
public function __construct() {
parent::__construct(); // Don't forget this, you'll never know what's being done in the constructor of the parent class you extended
}
}
After submitting the login details, it shows me the error:
Type error: Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\Model\UserAdmin given, called in /var/www/html/XXXXXX/vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php on line 379
I suppose that you required to add implements \Illuminate\Contracts\Auth\Authenticatable to your UserAdmin model class definition.
class UserAdmin extends Model implements
\Illuminate\Contracts\Auth\Authenticatable
You must use Authenticatable in User model
for example:
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
//your code
}
You must declared use AuthenticableTrait for Authenticatable interface.
For example :
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\Authenticatable as AuthenticableTrait;
use Illuminate\Database\Eloquent\Model;
class Company extends Model implements Authenticatable
{
use AuthenticableTrait;
Try and run 'composer dump-autoload' to check for "ambiguous User class resolution". It is likely you have two classes Defined as User Class.
use Illuminate\Foundation\Auth\AuthenticatesUsers;
Then in your model class, extends AuthenticatesUsers instead of Model.
You must extends Authenticatable class and implements JWTSubject in User model
For example :
class User extends Authenticatable implements JWTSubject {
Go to your Model and instead of extending Model, extend User
<?php
namespace App;
class Staff extends \Illuminate\Foundation\Auth\User
{
}
i want to share the channels variable in all the view but when i add the view::share method in the App service providers boot function it shows me the error of view class not found i am sharing the code and the error please help
<?php
namespace App\Providers;
use view;
use App\Channel;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
view::share('channels',Channel::all());
Schema::defaultStringLength(191);
}
I have a BaseRepository class with methods which will be valid for all Models. The only problem is, that the User model is derived from use Illuminate\Foundation\Auth\User. So it throws me a type error because the constructor requires an instance of Illuminate\Database\Eleoquent\Model. How can I solve the problem?
Here is my UserRepository.php:
namespace App\Repositories\User;
use App\Model\User; use App\Repositories\Base\BaseRepository;
class UserRepository extends BaseRepository {
public function __construct(User $user)
{
parent::__construct($user);
}
}
BaseRepository.php
namespace App\Repositories\Base;
use App\User;
use Illuminate\Database\Eleoquent\Model;
class BaseRepository {
public function __construct (Model $model) {
$this->model = $model;
}
public function all() {
return $this->model->orderBy('id','desc')->get();
}
}
This is the error: Type error:
Argument 1 passed to App\Repositories\Base\BaseRepository::__construct() must be an instance of Illuminate\Database\Eleoquent\Model, instance of App\User given, called in C:\wamp64\www\adblog\app\Repositories\User\UserRepository.php
Customize your User model like this
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements
AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword;
}
I have make an AdminController in App\Http\Controllers folder with an index method and the Request it is working fine, i type in url bar http://localhost/brosta/public/index and i take the path "index" to my browser it's ok!
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class AdminController extends Controller
{
public function index(Request $request)
{
$path = $request->path();
print_r($path);
return view('index');
}
But when i make the controller AdminController in a subfolder like App\Http\Controllers\Admin the requested path is not working. How can make it to work?
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Requests;
class AdminController extends Controller
{
public function index(Request $request)
{
$path = $request->path();
print_r($path);
return view('index');
}
}
Ok! Now i have a different problem with the Request! With this way is working
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class AdminController extends Controller
{
public function index(Request $request)
{
print_r($request->path());
}
}
But with this way is not working!
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class AdminController extends Controller
{
public function index()
{
$request = new Request;
print_r($request->path());
}
}
Try adding this line in your second controller.
use App\Http\Controllers\Controller;
Since you are in a different namespace you need to add the correct namespace for the Controller class.