【发布时间】:2021-05-26 15:46:10
【问题描述】:
有没有办法使用 Laravel 的紧凑方法传递类变量?
下面,我有$fields 变量,它通过构造方法初始化。
class EventTypeController extends Controller
{
protected $fields;
public function __construct()
{
$this->fields = Fields::all();
}
...
现在有没有办法使用紧凑方法传递上述变量?我试着像往常一样直接输入变量名,但是没有用。
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$event_types = EventType::all();
return view('event_types', compact('event_types', 'fields'));
}
【问题讨论】:
标签: laravel