如何解决用户数据未显示在 Laravel 的 html 表上
我正在尝试显示来自 mypgadmin 的注册用户,但在浏览器中没有显示。当使用 MysqL 数据库获取用户数据以显示在 HTML 表上时,一切正常,但是当使用 Postgresql 时,它没有在表上显示数据。
.env 文件
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:VNPNgqPxCOrUd2CH6+CoEVb/mRzIBmepWStqCigANbM=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=pgsql
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=core
DB_USERNAME=postgres
DB_PASSWORD=ajay
broADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
这是我的welcome.blade.PHP
<h1 class="mb4">Users</h1>
<br>
<table>
<thead >
<tr>
<td>Id</td>
<td>Name</td>
<td>Email</td>
<td>Menu roles</td>
</tr>
</thead>
<tbody>
@foreach($users as $a)
<tr>
<td>{{ $a-> id}}</td>
<td>{{ $a-> username }}</td>
<td>{{ $a-> email }}</td>
<td>{{ $a-> role_id }}</td>
</tr>
@endforeach
</tbody>
</table>
这是我的 web.PHP
<?PHP
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/',function () {
return view('welcome',['users' => App\User::all()]);
Route::get('welcome','UserController@registered');
});
<?PHP
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
class UsersController extends Controller
{
public function registered()
{
$users= User::get();
return view('welcome')->with('users',$users);
}
}
型号代码
<?PHP
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model{
protected $table="users";
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。