laravel UserController.php 第 39 行中的 FatalErrorException: Class 'App\Http\Controllers\User' not found
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28809150/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FatalErrorException in UserController.php line 39: Class 'App\Http\Controllers\User' not found
提问by Siddharth
I'm beginner in laravel. What I tried is composer dump-auto, but did not work.
我是 Laravel 的初学者。我试过的是 composer dump-auto,但没有用。
This Code is in Laravel 5.0 Every answer will be appreciated.
此代码在 Laravel 5.0 中,每个答案都将不胜感激。
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use View,
Response,
Validator,
Input,
Mail,
Session;
class UserController extends Controller {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
return view('pages.default');
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function insert()
{
$
$user = User::create(['u_name' => 'inputName', 'u_eml' => 'inputMail', 'u_contact' => 'inputContact']);
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
//
}
}
This is my Model: User.php
这是我的模型:User.php
<?php namespace App;
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;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract {
use Authenticatable, CanResetPassword;
protected $table = 'user';
public $timestamps = false;
}
回答by Laurence
Just add use App\User
in your top list - like this:
只需添加use App\User
到您的顶级列表中 - 像这样:
use App\User;
Oryou can change your controller code to be \App\User::create(...
(notice the \
at the beginning)
或者您可以将控制器代码更改为\App\User::create(...
(注意\
开头)
回答by Treasure
Simply add
只需添加
use App\user;
before the class declaration
在类声明之前
回答by Udara Gunawardhana
use App\User in the controller like this.
像这样在控制器中使用 App\User 。
<?php namespace App;
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 App\User;
class User extends Model implements AuthenticatableContract,CanResetPasswordContract {
use Authenticatable, CanResetPassword;
protected $table = 'user';
public $timestamps = false;
}