Php 登录后未定义变量的问题
我在Laravel5.7上有一个项目,我在登录后创建了一个自定义的admin(admin.blade.php)页面,只是在我的Users表上添加了userlevel列,我在admin.blade上有了下一个foreach admin.blade.phpPhp 登录后未定义变量的问题,php,laravel,laravel-5.7,Php,Laravel,Laravel 5.7,我在Laravel5.7上有一个项目,我在登录后创建了一个自定义的admin(admin.blade.php)页面,只是在我的Users表上添加了userlevel列,我在admin.blade上有了下一个foreach admin.blade.php @foreach($customers as $customer) <h3><b>{{$customer->count('id')}}</b></h3> @break @endforeac
@foreach($customers as $customer)
<h3><b>{{$customer->count('id')}}</b></h3>
@break
@endforeach
Route::get('/', function () {
if($user = Auth::user())
{
if(Auth::user()->userlevel == "admin"){
return view('/admin');
}
}
return view('/auth/login');
});
Route::get('/admin', 'HomeController@index')->name('admin');
use App\customers;
use App\pawns;
public function index()
{
$customers = customers::all();
$pawns = pawns::all();
return view('admin', compact('customers'), ['customers' => $customers,'pawns'=>$pawns]);
}
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
if ($guard == 'admin') {
return redirect()->route('/admin');
}
}
return $next($request);
}
HomeController.php
@foreach($customers as $customer)
<h3><b>{{$customer->count('id')}}</b></h3>
@break
@endforeach
Route::get('/', function () {
if($user = Auth::user())
{
if(Auth::user()->userlevel == "admin"){
return view('/admin');
}
}
return view('/auth/login');
});
Route::get('/admin', 'HomeController@index')->name('admin');
use App\customers;
use App\pawns;
public function index()
{
$customers = customers::all();
$pawns = pawns::all();
return view('admin', compact('customers'), ['customers' => $customers,'pawns'=>$pawns]);
}
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
if ($guard == 'admin') {
return redirect()->route('/admin');
}
}
return $next($request);
}
RedirectIfAuthenticated.php
@foreach($customers as $customer)
<h3><b>{{$customer->count('id')}}</b></h3>
@break
@endforeach
Route::get('/', function () {
if($user = Auth::user())
{
if(Auth::user()->userlevel == "admin"){
return view('/admin');
}
}
return view('/auth/login');
});
Route::get('/admin', 'HomeController@index')->name('admin');
use App\customers;
use App\pawns;
public function index()
{
$customers = customers::all();
$pawns = pawns::all();
return view('admin', compact('customers'), ['customers' => $customers,'pawns'=>$pawns]);
}
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
if ($guard == 'admin') {
return redirect()->route('/admin');
}
}
return $next($request);
}
如果我登录了,并且没有显示变量$customers的错误,我如何解决我再次打开的所有问题URL,这将显示admin.blade.php
感谢这是因为它无法使用客户变量,compact是用于合并数组的php函数,第三个参数用于合并数据,您不需要传递第三个参数,而是像这样更新主控制器中的代码
use App\customers;
use App\pawns;
public function index()
{
$customers = customers::all();
$pawns = pawns::all();
return view('admin',['customers'=>$customers,'pawns'=>$pawns]);
Or
return view('admin',compact('customers','pawns'));
}
compact('customers','pawns')
将是重复数组的简写……是的,两者都正确。您也可以将您的路由文件粘贴到这里吗?