Support the ongoing development of Laravel.io →
Database Eloquent Architecture

User.php

<?php namespace ESP; use Illuminate\Auth\Authenticatable; use Illuminate\Database\Eloquent\Model; use Illuminate\Auth\Passwords\CanResetPassword; use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; use DB; class User extends Model implements AuthenticatableContract, CanResetPasswordContract { use Authenticatable, CanResetPassword; protected $table = 'users'; protected $primaryKey = 'id'; public function companies(){ return $this->belongsToMany('ESP\Company', 'company_user', 'user_id', 'company_id'); } public function scopeUsername($query, $username){ return $query->where('username', '=', $username); } } ?>

Company.php

<?php namespace ESP; use Illuminate\Database\Eloquent\Model; use DB; class Company extends Model { protected $table = 'companies'; protected $primaryKey = 'id'; public function users(){ return $this->belongsToMany('ESP\User'); } } ?>

LoginController.php

<?php namespace ESP\Http\Controllers\Login; use ESP\Http\Requests; use ESP\Http\Controllers\Controller; use ESP\CustomClass\LDAP\adLDAP; // Import Illuminate Manually use Illuminate\Http\Request; use Illuminate\Support\Facades\Redirect; use ESP\LoginAttempts; use ESP\Helpers\UtilityHelper; use ESP\User; use DB; use Auth; use Session; use View; use Paginator; use DateTime; use Input; /** * LoginController */ class LoginController extends Controller { private function _authenticateClient($username, $password) { $g = User::with('companies') ->where( 'username', $username ) ->where( 'password', md5( $password ) ) ->get(); dd($g); } } Error has something like this. BadMethodCallException in Builder.php line 2405: Call to undefined method Illuminate\Database\Query\Builder::companies() I can't even make use of the local scope Username on my controller call. This models are working perfectly fine on my laravel 5.1. But im trying to migrate my codebase to 5.3 and im stuck with this issues.
Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.