我不知道这个错误是什么原因造成的。我的代码中没有更改任何内容。但是当我进入我的搜索视图时。它总是返回未定义的属性错误。当我尝试预先我的表数据中的所有列时,会出现此错误。我已经解决了这个错误。因为找不到所选选项的$id
。但这次我无法修复它。
错误:
未定义属性:stdClass :: $ id(查看:C:\ Users \ JohnFrancis \ LaravelFrancis \ resources \ views \ document \ show.blade.php)
查看
show.blade.php - 此视图将列出表格中的所有值。
@section ('content')
<div class = "col-md-12">
<table class = "table">
<thead>
<tr>
<th>Title</th>
<th>Content</th>
<th>Category</th>
<th>Sender</th>
<th>Date Received</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach ($documentLists as $list)
<tr class = "info">
<td>{{ $list->title }}</td>
<td>{{ strip_tags(substr($list->content, 0, 50)) }} {{ strlen($list->content) > 50 ? "..." : '' }}</td>
<td>{{ $list->category_type }}</td>
<td>{{ $list->username }}</td>
<td>{{ date('M j, Y', strtotime($list->dateReceived)) }}</td>
<td>
<a href = "{{ route ('document.read', $list->id) }}"><button type = "submit" class = "btn btn-info">Read</button></a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection
read.blade.php - 它将重定向到当前选择的视图。
<!--DOCUMENT CONTROLLER-->
<div class = "col-md-6">
<form class = "vertical">
<div class = "form-group">
<textarea id = "content">{{ $documentLists->content }}</textarea>
</div>
<div class = "form-group">
<button type = "submit" class = "btn btn-success">Approve</button>
</div>
</form>
</div>
控制器
//SHOW
public function showDocuments()
{
$documentLists = DB::table('document_user')->select('documents.title', 'documents.content', 'categories.category_type', 'users.username', 'document_user.dateReceived')
//Table name //PK //FK
->join('users', 'users.id', '=', 'document_user.sender_id')
->join('documents', 'documents.id', '=', 'document_user.document_id')
->join('categories', 'categories.id', '=', 'documents.category_id')
->where('sender_id', '!=', Auth::id())
->where('user_id', '!=', Auth::id())->get();
//VIEW
return view ('document.show')->with('documentLists', $documentLists);
}
//READ
public function readDocuments($id)
{
//Find the document in the database and save as var.
$documentLists = Document::find($id);
return view ('document.read')->with('documentLists', $documentLists);
}
路由
Route::get('/show',
[
'uses' => '\App\Http\Controllers\DocumentController@showDocuments',
'as' => 'document.show',
'middleware' => 'auth',
]);
Route::get('/receive/documents/{id}',
[
'uses' => '\App\Http\Controllers\DocumentController@readDocuments',
'as' => 'document.read',
'middleware' => 'auth',
]);
答案 0 :(得分:2)
在下面你没有选择id
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hallo, wie heißt du?");
string name = Console.ReadLine();
Program a = new Program();
a.nameCheck(name);
Console.WriteLine("Hallo " + name);
Console.ReadLine();
}
private void nameCheck(string n)
{
if (n == "")
{
Console.WriteLine("Geben Sie einen Namen ein");
n = Console.ReadLine();
}
}
}
但请在您的刀片中调用$documentLists = DB::table('document_user')->select('documents.title', 'documents.
答案 1 :(得分:0)
$documentLists = DB::table('document_user')->select('documents.id','documents.title', 'documents.content', 'categories.category_type', 'users.username', 'document_user.dateReceived');
你需要选择列文档。但是你错过了它