我不确定为什么会这样,但也许有人可以提供帮助。
我运行Windows 8.1机器并使用WAMP。我最后做的是为Windows安装composer,并使用作曲终端(对不起,如果条款错误,希望它有意义)我将改为我的根网站目录并通过键入
安装laravelcomposer create-project laravel / laravel testapp
一切都安装 - 但我看到它报告说建议安装很多依赖项。我以为会自动抓住这些?
无论如何,安装后它会生成一把钥匙,然后继续学习laravel。我设置了一个控制器并使用现有的User.php模型 - 但是当我看到这个模型时,它没有getAuth方法......我假设它来自symphony依赖项。直到我开始使用Auth :: attempt()并让它总是返回false时,我才意识到这一点。甚至在用户名和输入:: get('密码')中进行硬编码(在登录时不进行哈希处理,因为auth尝试从我读过的内容中执行,但在保存到数据库时进行哈希处理。)
我想我的问题是为什么不安装这些依赖项,这些是为什么缺少User.php方法,并且由于缺少这些方法,会导致我的返回错误问题吗?
我应该注意到,通过下载master-laravel.zip文件并在那里打开User.php,看到它没有任何方法,我得到了所有这些。
还有一件事,只是为了增加我的故事 - 我甚至观看并重新观看了Jeffrey Way的laracasts免费课程,跟随信件的所有内容,仍然导致了这一点!
帮助!太令人沮丧了!
User.php MODEL
<?php
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
protected $fillable = array('username', 'password', 'email');
use UserTrait, RemindableTrait;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password', 'remember_token');
}
UsersController.php
<?php
class UsersController extends \BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
return View::make('users.create');
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
// manual way
// Validate input
$validation = Validator::make(Input::all(), ['username' => 'required|min:6','email' => 'required|min:4|email','password' => 'required|min:6']);
// check if validation fails
if ($validation->fails())
{
return Redirect::back()->withInput()->withErrors($validation);
}
else
{
// method #1
// create new user in db
//$user = new User;
//$user->username = Input::get('username');
//$user->email = Crypt::encrypt(Input::get('email'));
//$user->password = Hash::make(Input::get('password'));
//$user->save();
// this is eloquent way - auto adds timestamps to db
$user = User::create(array(
'username' => Input::get('username'),
'email' => Crypt::encrypt(Input::get('email')),
'password' => Hash::make(Input::get('password'))
));
}
return Redirect::to('/');
}
/**
* 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)
{
//
}
SessionsController.php
<?php
class SessionsController extends \BaseController {
/**
* -Store a newly created resource in storage.
* -Create session to log user in
*
* @return Response
*/
public function store()
{
// Get the users login information from input boxes and pass as a array to auth:attempt method
$info = Auth::attempt(array('username' => Input::get('username'),'password' => Input::get('password')));
if ($info)
{
return 'yay!';
}
else
{
return dd($info);
}
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
//
}
/**
* Show the form for logging in.
*
* @return Response
*/
public function login()
{
return View::make('sessions.login');
}
创建视图
<div class="col-md-12">
<div class="accountPanel">
{{ Form::open(array('route' => 'users.store')) }}
<div class="form-group">
<h4><label for="username">Create a Username</label></h4>
<input id="username" class="form-control" type="text" name="username" />
{{ $errors->first('username', '<p class="text-danger">:message</p>') }}
</div>
<div class="form-group">
<h4><label for="email">Enter your Email Address</label></h4>
<input id="email" class="form-control" type="email" name="email" />
{{ $errors->first('email', '<p class="text-danger">:message</p>') }}
</div>
<div class="form-group">
<h4><label for="password">Create a Password</label></h4>
<input id="password" class="form-control" type="password" name="password" />
{{ $errors->first('password', '<p class="text-danger">:message</p>') }}
</div>
<button type="submit" class="btn btn-primary">Create Your Profile</button>
{{ Form::close() }}
</div>
登录视图
<div class="col-md-12">
<div class="accountPanel">
{{ Form::open(array('route' => 'sessions.store')) }}
<div class="form-group">
<h4><label for="username">Enter your Username</label></h4>
<input id="username" class="form-control" type="text" name="username" />
</div>
<div class="form-group">
<h4><label for="password">Enter a Password</label></h4>
<input id="password" class="form-control" type="password" name="password" />
</div>
<button type="submit" class="btn btn-primary">Sign In</button>
{{ Form::close() }}
</div>
</div>
如果您需要视图,请告诉我,但他们所做的只是创建,发布到users.store路由,登录时会发布到sessions.store路由。