Siddharth
Siddharth

Reputation: 1769

FatalErrorException in UserController.php line 39: Class 'App\Http\Controllers\User' not found

I'm beginner in laravel. What I tried is composer dump-auto, but did not work.

This Code is in Laravel 5.0 Every answer will be appreciated.

<?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

<?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;    
}

Upvotes: 3

Views: 9121

Answers (3)

Dilshan Dilip
Dilshan Dilip

Reputation: 759

use App\User in the controller like this.

<?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;    
}

Upvotes: 0

Treasure
Treasure

Reputation: 92

Simply add

use App\user;

before the class declaration

Upvotes: 0

Laurence
Laurence

Reputation: 60058

Just add use App\User in your top list - like this:

use App\User;

Or you can change your controller code to be \App\User::create(... (notice the \ at the beginning)

Upvotes: 7

Related Questions