【发布时间】:2020-09-23 08:46:54
【问题描述】:
请帮助我。我是 Laravel 的新手。 我正在尝试从我的表中查看数据,但它显示了这个错误。我已经在控制器中定义了模型。我将 index.blade.php 放在文件中。 这些是我的代码。我使用 Laravel 7
app -> User.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
protected $table = "users";
}
app -> Http -> 控制器 -> AdminController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
class AdminController extends Controller
{
public function user(Request $request){
return view('Admin/Form User/index');
}
public function show()
{
$users = User::all();
return view('index', ['index' => $users]);
}
}
路由 -> web.php
Route::get('/Admin/Form User/index', 'AdminController@user');
Route::get('/index', 'AdminController@show');
资源 -> 视图 -> main.blade.php
<a href="Admin/Form User/index" class="btn btn-primary" role="button">Form User</a>
资源 -> 视图 -> 管理员 -> 表单用户 -> index.blade.php
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Id</th>
<th>Class</th>
<th>Name</th>
<th>Option</th>
</tr>
</thead>
<tbody>
@foreach($users as $u)
<tr>
<td>{{ $u->class }}</td>
<td>{{ $u->name }}</td>
<td>
<a>Edit</a>
<a>Delete</a>
</td>
</tr>
@endforeach
</tbody>
</table>
谢谢
【问题讨论】:
标签: model-view-controller crud php-7 laravel-7