登录表格不起作用Laravel 5.2

时间:2016-04-01 17:55:50

标签: php laravel-5 laravel-5.2

我在eComerace应用程序中创建了一个登录表单和一个注册表单,但是当我提交登录表单(登录)时,它什么也没有返回!我输入的用户名和密码正确但我的登录页面无效。

路线

Route::get('users/signin', 'UsersController@getSignin');
Route::post('users/signin', 'UsersController@postSignin');

Route::resource('users', 'UsersController');


Route::get('/', 'StoreController@index');
Route::get('store/category/{id}', 'StoreController@getCategory');
Route::get('store/search', 'StoreController@getSearch');

Route::get('/admin', function () {
    return view('welcome');
});
Route::resource('store', 'StoreController');
Route::resource('admin/categories', 'CategoriesController');
Route::resource('admin/products', 'ProductsController');

UsersController

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Auth;
use App\Http\Requests;
use App\Category;
use App\product;
use Hash;
use View;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;

class UsersController extends Controller
{
    public function __construct(){
        parent::__construct();
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function getSignin(){

        return View::make('users.signin');
    }

    public function index()
    {
        return Hash::make('ifti');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return View::make('users.newaccount');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
            $user = new User;
            $user->name = Input::get('name');
            $user->email = Input::get('email');
            $user->password = Hash::make(Input::get('password'));
            $user->save();
            return Redirect::to('users/signin')->with('message','Thank you for creating new account.Sign in now');
    }




    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
    public function getSignout(){
        Auth::logout();
        return Redirect::to('users/signin')->with('message','Signouted!');
    }

    public function postSignin(){
        $password = Hash::make(Input::get('password'));
        $credentials = array('name' => Input::get('name'), 'password' => $password);

        if(Auth::attempt($credentials)){
            return Redirect::to('http://localhost/ecom/')->with('message','Thanks for signin');
        }
        return Redirect::to('users/signin')->with('message','Was Incorrect DATA!');
    } 


}

登录视图

    {!! Form::open(array('url' => 'users/signin' , 'method' => 'post')) !!} 

                          <div class="form-group">
                            <label for="username">User Name:</label>
                            {!! Form::text('name') !!}
                          </div>

                          <div class="form-group">

                            <label for="username">Password:</label>
                            {!! Form::password('password') !!}
                          </div>

                          <button type="submit" class="btn btn-default">Sign IN</button>
  {!! Form::close() !!}

新帐户视图

<div class="col-md-8 col-lg-8 col-sm-12 col-xs-12">
                   {!! Form::open(array('url' => 'users/create' , 'method' => 'post')) !!} 

                      <div class="form-group">
                        <label for="username">User Name:</label>
                        <input type="username" class="form-control" name="name" id="name">
                      </div>
                      <div class="form-group">
                        <label for="email">Email:</label>
                        <input type="email" class="form-control" name="email" id="name">
                      </div>
                      <div class="form-group">
                        <label for="password">Password:</label>
                        <input type="password" class="form-control" name="password" id="name">
                      </div>

                      <button type="submit" class="btn btn-default">Create New Account</button>
                   {!! Form::close() !!}

    </div>

0 个答案:

没有答案