Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从控制器向Laravel 7中的视图发送数据_Php_Html_Sql_Laravel_Web - Fatal编程技术网

Php 从控制器向Laravel 7中的视图发送数据

Php 从控制器向Laravel 7中的视图发送数据,php,html,sql,laravel,web,Php,Html,Sql,Laravel,Web,我想将我的数据从controller发送到xedit.blade.php,但我收到了相同的错误: Undefined variable: users 在控制器中: public function index3() { $users=User::all(); return view('xedit')->with('users' => $users); } 路线: Route::get('/index3','Admin\UsersCont

我想将我的数据从controller发送到xedit.blade.php,但我收到了相同的错误:

 Undefined variable: users
在控制器中:

public function index3()
    {
        $users=User::all();

    return view('xedit')->with('users' => $users);

    }
路线:

Route::get('/index3','Admin\UsersController@index3');

我想在blade中使用$users。可能存在路由问题?

您的代码逻辑非常完美,我想您必须对路由使用正确的命名,因为采用了Laravel标准

Route::get('/admin/show','Admin\UsersController@index')-name('admin.show');

public function index()
{
    $users = User::all();
    return view('xedit')->with('users' => $users);
}
有鉴于此,blade采用如下专业方法

@isset($users)
 ... loop ...
@endisset()

使用转储和模具功能dd$users发送至查看前检查记录

您的代码逻辑非常完美,我想您必须对路由使用正确的命名,因为使用了Laravel标准

Route::get('/admin/show','Admin\UsersController@index')-name('admin.show');

public function index()
{
    $users = User::all();
    return view('xedit')->with('users' => $users);
}
有鉴于此,blade采用如下专业方法

@isset($users)
 ... loop ...
@endisset()
使用转储和模具功能dd$users发送至查看前检查记录

在您的索引方法中

public funtion index()
{
     $users=User::all();
     return view('xedit', compact('users'));
}
在您的视图中添加$users

<table>
    @foreach ($users as $item)
        <tr>
            <td>{{ $item->id }}</td>
            <td>{{ $item->name }}</td>
        </tr>
    @endforeach
</table>
在您的索引方法中

public funtion index()
{
     $users=User::all();
     return view('xedit', compact('users'));
}
在您的视图中添加$users

<table>
    @foreach ($users as $item)
        <tr>
            <td>{{ $item->id }}</td>
            <td>{{ $item->name }}</td>
        </tr>
    @endforeach
</table>

想发表评论,但没有50%的声誉


替换“用户”=>$users;这与['users'=>$users]有关;当您使用=>

时,您想发表评论,但没有50%的声誉

替换“用户”=>$users;这与['users'=>$users]有关;当您使用=>

时,您使用的是箭头符号=>而不使用数组。声明return语句的正确方法是返回视图'xedit'->with['users'=>$users];。或者,您可以使用这个问题的一个答案中所示的compact。您使用的是箭头符号=>而不使用数组。声明return语句的正确方法是返回视图'xedit'->with['users'=>$users];。或者,您可以使用这个问题的一个答案中所示的compact。