找不到“app \ Student”类

时间:2017-08-13 08:16:14

标签: php laravel

当我注册时显示此错误-----

Class 'app\Student' not found
in CustomLoginController.php (line 57)

代码:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Illuminate\Support\Facades\Validator;

use app\Student;

use Redirect;

use Session;

use Illuminate\Support\Facades\Input;

class CustomLoginController extends Controller

{

public function ShowLoginForm()

{
    return view('custom.login');
}
public function login(Request $request)
{
    return 'login';
}
public function ShowRegisterForm()

{

    return view('custom.register');

}

public function register(Request $request)

{

     $rules = array(

        'first_name' => 'required|min:5',

        'last_name' =>  'required|min:5',

        'email'            => 'required|email|unique:students',     // required and must be unique in the students table
        'password'         => 'required|min:6',
        'password_confirm' => 'required|same:password'
    );
     $messages = [
        'first_name.required' => 'Please enter first name.',
        'first_name.min' => 'First name should be atleast 5 characters.',
        'last_name.required' => 'Please enter last name.',
        'last_name.min' => 'Last name should be atleast 5 characters.',
        'email.required' => 'Please enter email address.',
        'email.email' => 'Please enter a valid email address.',
        'email.unique' => 'This email address has been already used. Please try another',
        'password.required' => 'Please enter password.',
        'password.min' => 'Password should be atleast 6 characters.',
        'password_confirm.required' => 'Please enter confirm password.',
        'password_confirm.same' => 'Password do not match.',
    ];

    $validator = Validator::make(Input::all(), $rules ,$messages);

    if ($validator->fails()) {
        return redirect('/custom-register')
                ->withErrors($validator)
                ->withInput(Input::except('password', 'password_confirm'));
    }

    $students = new Student();
    $students->first_name = Input::get('first_name');
    $students->last_name = Input::get('last_name');
    $students->email = Input::get('email');
    $students->password = Hash::make(Input::get('password'));
    $students->save();

   // Auth::login($students);
    return redirect()->route('/');
}
}

2 个答案:

答案 0 :(得分:0)

它应该是App\Student而不是app\Student

答案 1 :(得分:-2)

添加控制器 $users = \App\Models\Student::all();