【问题标题】:I try to pass the data within the welcome.blade but "Cannot use positional argument after named argument"我尝试在 welcome.blade 中传递数据,但“不能在命名参数后使用位置参数”
【发布时间】:2021-10-23 18:42:57
【问题描述】:

我正在尝试将数据传递给 welcome.blade,但它给出了这个错误。

enter image description here

laravel 8 中是否有某种语法或缺少某些包?

【问题讨论】:

    标签: php laravel laravel-8


    【解决方案1】:

    试试这个:

    return view('welcome', compact('data'));
    

    【讨论】:

    • 是的,谢谢。但是,如果我在欢迎页面中调用它时出现另一个语法错误,你能纠正我吗?我试过这个

      {{$name}}

      name is an index of data = $data['name']
    【解决方案2】:

    我认为您有三种方法可以在 laravel 8 中传递数据以查看

    1-使用紧凑方法:

    return view('welcome', compact('data'));
    

    2-使用with方法:

    return view('welcome')->with('data', $data);
    

    3-像这样直接解析数据:

    return view('welcome', ["data"=>$data]);
    

    【讨论】:

    • 是的,但现在的问题是如何在欢迎页面内的

      内调用它 我试过这个:

      {{$name}}

      $ name 是 $data=['name'] 的关键你有什么线索
    • @SherifNasser try :

      {{$data['name']}}

      你的数组定义是错误的。像这样定义数组: $data = array();
    猜你喜欢
    • 2021-08-12
    • 1970-01-01
    • 1970-01-01
    • 2013-07-28
    • 2019-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多