我的app / Models / AdminModel.php中的代码:
<?php
namespace App\models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
class AdminModel extends Authenticatable
{
protected $table='admin';
protected $primaryKey='admin_id';
public function getAuthPassword(){
return $this->admin_pass;
}
public function getAdminInfo(){
$admin=DB::table("admin")->get();
return $admin;
}
}
?>
我的app / http / controllers / AdminController.php中的代码:
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use Hash;
use Illuminate\Support\Facades\Validator;
use Auth;
use Request;
use Captcha;
use App\Models\AdminModel;
class AdminController extends Controller
{
public function index()
{
if (!Auth::check()) {
return redirect('admin/login');
exit;
}
$admin=Admin::getAdminInfo(); //here is where the error occurs
exit;
return view('admin_index');
}
}
?>
错误说明: AdminController.php第23行中的FatalErrorException: 未找到类'App \ Http \ Controllers \ Admin'
我的问题是什么?感谢
答案 0 :(得分:1)
那是因为您的班级名称是AdminModel
。所以,而不是:
Admin::getAdminInfo()
你应该使用:
AdminModel::getAdminInfo()
另外,请注意您静态调用该方法,因此您必须将其定义为静态:
public static function getAdminInfo()
答案 1 :(得分:0)
检查您的路线并致电完整
AdminModel::getAdminInfo();
而不是
Admin::getAdminInfo();
并且功能在AdminModel中是静态的
public static function getAdminInfo(){
$admin=DB::table("admin")->get();
return $admin;
}