未定义的属性:Illuminate \ Support \ Facades \ Request :: $ email

时间:2019-05-01 08:02:51

标签: laravel

我是laravel的新手,我正在尝试制作一个简单的注册和登录表单,注册表单在数据库中注册用户,然后登录表单登录用户,但是在这里,我遇到此错误是为了解决此问题很多小时调查了很多资源,但无法弄清楚,任何帮助将不胜感激。谢谢

错误:未定义的属性:Illuminate \ Support \ Facades \ Request :: $ email

刀片

@extends("layouts.master")

@section('title')
  My page
@endsection

@section('content')
  <div class="row">
    <div class="col-md-6">
      <h3>Sign-Up</h3>
      <form action="{{ route('signup') }}" method="post">

        <div class="form-group">
          <label for="email">Your email</label>
          <input class="form-control" type="text" name="email" id="email">
        </div>

        <div class="form-group">
          <label for="first_name">First Name</label>
          <input class="form-control" type="text" name="first_name" id="first_name">
        </div>

        <div class="form-group">
          <label for="password">Password</label>
          <input class="form-control"  type="password" name="password" id="password">
        </div>

        <button type="sumbit" class="btn btn-primary">sumbit</button>
        <input type="hidden" name="_token" value="{{ Session::token() }}">

      </form>
    </div>

    <div class="col-md-6">
      <h3>Login </h3>
      <form action="{{ route('signin') }}" method="post">

        <div class="form-group">
          <label for="email">Your email</label>
          <input class="form-control" type="text" name="email" id="email">
        </div>

        <div class="form-group">
          <label for="password">Password</label>
          <input class="form-control"  type="password" name="password" id="password">
        </div>

        <button type="sumbit" class="btn btn-primary">sumbit</button>
        <input type="hidden" name="_token" value="{{ Session::token() }}">

      </form>
    </div>
  </div>
@endsection
use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});


Route::post('/signup', [
    'uses' => 'UserController@postSignUp',
    'as' => 'signup'

]);


Route::post('/signin', [
    'uses' => 'UserController@postSignIn',
    'as' => 'signin'

]);

Route::get('/dashboard', [
    'uses' => 'UserController@getdashboard',
    'as' => 'dashboard'

]);


Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

控制器

namespace App\Http\Controllers;

use App\Http\Requests;
use App\User;
use App\UserTypes;

use Auth;
use Hashids;
use Redirect;
use Request;
use Hash;


class UserController extends controller
{
    public function getdashboard()
    {
        return view('dashboard');
    }

    public function postSignUp(Request $request)
    {
        $email = $request->email;
        $first_name = $request->first_name;
        $password = bcrypt($request->password);


        $user = new User();
        $user->email = $email;
        $user->first_name = $first_name;
        $user->password = $password;

        $user->save();
        return redirect()->route('dashboard');
    }

    public function postSignIn(Request $request)
    {
        if (Auth::attempt(['email' => $request->email, 'password' => $request->password])) {
            return redirect()->route('dashboard');
        }
        return redirect()->back();
    }
}

2 个答案:

答案 0 :(得分:0)

更改控制器功能

use Illuminate\Http\Request;
public function postSignUp(Request $request)
{
    $email = $request->input('email');
    $first_name = $request->input('first_name');
    $password = bcrypt($request->input('password'));


    $user = new User();
    $user->email = $email;
    $user->first_name = $first_name;
    $user->password = $password;

    $user->save();
    return redirect()->route('dashboard');
}
public function postSignIn(Request $request)
{
    if (Auth::attempt(['email' => $request->input('email'), 'password' => $request->input('password')])) {
        return redirect()->route('dashboard');
    }
    return redirect()->back();
}

答案 1 :(得分:0)

这有助于导入使用Illuminate \ Http \ Request;而不是使用请求;

use Illuminate\Http\Request; 

class UserController extends controller{
}