douci2516 2016-09-29 23:55
浏览 106
已采纳

使用compact从控制器传递数组以查看laravel

I'm using laravel 5.3 (make:auth automatic register and user authentication generator), and I would like to let user choose their tags in the registration form.

I wanna pass $tags = App\Tag::all(); to the register.blade.php file located in views\authegister.blade.php.

I found this method:

public function showRegistrationForm()
{
    return view('auth.register');
}

and I would like to do:

public function showRegistrationForm()
{
    $tags = App\Tag::all();
    return view('auth.register', compact($tags));
}

but I get undefined variable 'tags' when trying to reach the register.blade.php file.

  • 写回答

3条回答 默认 最新

  • dqjcb132285 2016-09-30 00:12
    关注

    Don't feed the variable itself, provide the variable name when using compact.

    return view('auth.register', compact('tags'));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理