這是create_users_table.php當創建在我nerd_table一個書呆子,我得到以下錯誤
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
$table->integer('nerd_level');
});
}
QueryException in Connection.php line 647: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'nerd_level' in 'field list' (SQL: insert into
users
(name
,nerd_level
,updated_at
,created_at
) values (dasdasd, [email protected], 1, 2017-03-31 15:41:51, 2017-03-31 15:41:51))
我的代碼,當我嘗試編輯一個書呆子,我得到了以下錯誤:
ErrorException in 17afaeb4afd6b4276e6af6ff12921ab25d74a9cc.php line 22: Trying to get property of non-object (View: /var/www/vhosts/vincentspage.tk/httpdocs/Laravel/resources/views/nerds/edit.blade.php)
這是edit.blade.php我的代碼:
<!DOCTYPE html>
<html>
<head>
<title>Look! I'm CRUDding</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap
/3.0.0 /css/bootstrap.min.css">
</head>
<body>
<div class="container">
<nav class="navbar navbar-inverse">
<div class="navbar-header">
<a class="navbar-brand" href="{{ URL::to('nerds') }}">Nerd Alert</a>
</div>
<ul class="nav navbar-nav">
<li><a href="{{ URL::to('nerds') }}">View All Nerds</a></li>
<li><a href="{{ URL::to('nerds/create') }}">Create a Nerd</a>
</ul>
</nav>
<h1>Edit {{ $nerd->name }}</h1>
<!-- if there are creation errors, they will show here -->
{{ HTML::ul($errors->all()) }}
{{ Form::model($nerd, array('route' => array('nerds.update',
$nerd->id), 'method' => 'PUT')) }}
<div class="form-group">
{{ Form::label('name', 'Name') }}
{{ Form::text('name', null, array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('email', 'Email') }}
{{ Form::email('email', null, array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('nerd_level', 'Nerd Level') }}
{{ Form::select('nerd_level', array('0' => 'Select a Level', '1' =>
'Sees Sunlight', '2' => 'Foosball Fanatic', '3' => 'Basement
Dweller'), null, array('class' => 'form-control')) }}
</div>
{{ Form::submit('Edit the Nerd!', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
</div>
</body>
</html>
當我嘗試刪除一個書呆子這是錯誤:
FatalErrorException in NerdController.php line 128: Call to a member function delete() on null
回報重定向是php線128
public function destroy($id)
{
// delete
$nerd = User::find($id);
$nerd->delete();
// redirect
Session::flash('message', 'Successfully deleted the nerd!');
return Redirect::to('nerds');
}
此錯誤可能是有利可圖的其他人誰也有類似的問題,讓他們知道什麼改變他們的代碼。或者不要向誰先讀它的人發生類似的錯誤。
任何人都可以幫助我嗎?
親切的問候,
文森特
你能在NerdController.php上顯示第128行嗎?此外,無論刪除被調用,你可以顯示一切,看看如何變量爲空? – Goose
創建表之後,請驗證nerd_level是否以列的形式存在。 – mkaatman
沒有看到你的php代碼和你的sql表的基本結構,這使得它很難幫助,你也使用什麼變種的SQL? – Jpsh