【问题标题】:Facade\Ignition\Exceptions\ViewException Trying to get property 'price' of non-objectFacade\Ignition\Exceptions\ViewException 试图获取非对象的属性“价格”
【发布时间】:2020-08-20 10:21:20
【问题描述】:

'这是我的控制器''当我单击对象时我需要帮助我想从 phpmyadmin 获取行数据谢谢大家'

公共函数存储(请求 $request){

    $this->middleware('auth');


    $tours = new tour();

    $tours->name=$request->input('name');
    $tours->date=$request->input('date');
    $tours->price=$request->input('price');
    $tours->hotel=$request->input('hotel');
    $tours->created_at=$request->input('created_at');
    $tours->service=$request->input('service');
    $tours->some=$request->input('some');


    if($request->hasFile('picture')){
        $file=$request->file('picture');
        $extension =$file->getClientOriginalName();
        $filename =time() .'.'.$extension;
        $file->move(public_path('images'),$filename);
        $tours->picture=$filename;

    }

    $tours->save();
    return redirect('admin/tour');       
}

'这是我的看法'

                    <div class="bc" style=" border-radius: 4px; width: 70%; height:45rem;">
                            <h4 style="text-align: center; position: relative; top:15px;">Tur Haqqında Məlumat</h4>
                            <strong style=" position: relative; top:15px;">Qiymət</strong>
                            <p style=" position: relative; top:15px;  width: 100%; font-weight: 400; font-family: 'Times New Roman', Times, serif;" name='price'>{{$tour->price}} AZN</p>
                            <hr/>

【问题讨论】:

  • 你的问题很不清楚,试着描述一下你想要达到的目标,会发生什么?
  • 错误在{{ $tour-&gt;price }}$tour 对象必须为空。尝试dd($tour) 并检查它是否为空。为了使变量在视图中起作用,您需要从控制器传递它们。在这种情况下,您需要将$tour 传递给视图。

标签: php laravel


【解决方案1】:

您需要将$tours 传递给您的视图:

return redirect('admin/tour', ['tour'=> $tours]);    

顺便说一句,我会使用 $tour 而不是您现在在控制器中使用的复数版本 $tours

【讨论】:

    猜你喜欢
    • 2020-09-24
    • 2020-09-17
    • 2020-08-09
    • 1970-01-01
    • 2020-10-17
    • 2020-09-07
    • 2020-04-23
    • 2020-05-10
    • 2023-04-01
    相关资源
    最近更新 更多