Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.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 试图得到非ojbect。首先()。拉维尔 页面控制器 $Sport_Post=\App\Post::All()->其中('category_id','=',3)->first(); $Sport\u Posts=\App\Post::All()->其中('category\u id','=',3)->跳过(1); 返回视图('welcome',compact('Sport_Post','Sport_Posts'); 页码代码 @forelse($Sport_Post as$Post) 图像}}“>_Php_Laravel - Fatal编程技术网

Php 试图得到非ojbect。首先()。拉维尔 页面控制器 $Sport_Post=\App\Post::All()->其中('category_id','=',3)->first(); $Sport\u Posts=\App\Post::All()->其中('category\u id','=',3)->跳过(1); 返回视图('welcome',compact('Sport_Post','Sport_Posts'); 页码代码 @forelse($Sport_Post as$Post) 图像}}“>

Php 试图得到非ojbect。首先()。拉维尔 页面控制器 $Sport_Post=\App\Post::All()->其中('category_id','=',3)->first(); $Sport\u Posts=\App\Post::All()->其中('category\u id','=',3)->跳过(1); 返回视图('welcome',compact('Sport_Post','Sport_Posts'); 页码代码 @forelse($Sport_Post as$Post) 图像}}“>,php,laravel,Php,Laravel,{{$post->created_at}}{{{$post->short_desc} @空的 没有时间没有帖子 @endforelse 错误从src=“{{$post->image}}”开始;出了什么问题?如何修复它 内部控制器 Page Controller $Sport_Post = \App\Post::All()->Where('category_id','=',3)->first(); $Sport_Posts = \App\Post::All()->Where('


{{$post->created_at}}
{{{$post->short_desc}

@空的
没有时间
没有帖子

@endforelse
错误从src=“{{$post->image}}”开始;出了什么问题?如何修复它

内部控制器

Page Controller
$Sport_Post = \App\Post::All()->Where('category_id','=',3)->first();
$Sport_Posts = \App\Post::All()->Where('category_id','=',3)->skip(1);
return view('welcome', compact('Sport_Post','Sport_Posts'));
Code of page
                                            @forelse($Sport_Post as $post)
        <div  id="content-number-1" class="col-12 col-md-8 col-lg-8 home-post1 content-number-1">
            <div class=""><img class="content-one-img content-img-chapter" src="{{$post->image}}"></div>
            <div class="content-text-img p-3"><p><a class="m-0 underImage aTagsHover" style="font-size: 20px" href="/inside/{{$post->id}}">{{$post->title}}</a><br><span class="date-font"><i class="fa fa-clock-o" aria-hidden="true"></i>{{$post->created_at}}</span><span class="underBusiness"><br>{{$post->short_desc}}</span></p></div>
        </div>
        @empty
        <div  id="content-number-1" class="col-12 col-md-8 col-lg-8 home-post1 content-number-1">
            <div class="content-one-img content-img-chapter"></div>
            <div class="content-text-img p-3"><p><a class="m-0 underImage aTagsHover" style="font-size: 20px" href="#">No post</a><br><span class="date-font"><i class="fa fa-clock-o" aria-hidden="true"></i>No time</span><span class="underBusiness"><br>No post</span></p></div>
        </div>
        @endforelse
在刀片文件中,不需要for循环,因为$Sport_Post是单个对象而不是集合,所以修改刀片代码如下:

$Sport_Post = \App\Post::Where('category_id','=',3)->first();
@if(isset($Sport_Post))
图像}}“>

{{$Sport\u Post->created\u at}
{{{$Sport\u Post->short\u desc}

@否则
没有时间
没有帖子

@恩迪夫
无需全部()使用以下命令更改代码

@if(isset($Sport_Post))
         <div  id="content-number-1" class="col-12 col-md-8 col-lg-8 home-post1 content-number-1">
            <div class=""><img class="content-one-img content-img-chapter" src="{{$Sport_Post->image}}"></div>
            <div class="content-text-img p-3"><p><a class="m-0 underImage aTagsHover" style="font-size: 20px" href="/inside/{{$Sport_Post->id}}">{{$Sport_Post->title}}</a><br><span class="date-font"><i class="fa fa-clock-o" aria-hidden="true"></i>{{$Sport_Post->created_at}}</span><span class="underBusiness"><br>{{$Sport_Post->short_desc}}</span></p></div>
        </div>
@else
        <div  id="content-number-1" class="col-12 col-md-8 col-lg-8 home-post1 content-number-1">
            <div class="content-one-img content-img-chapter"></div>
            <div class="content-text-img p-3"><p><a class="m-0 underImage aTagsHover" style="font-size: 20px" href="#">No post</a><br><span class="date-font"><i class="fa fa-clock-o" aria-hidden="true"></i>No time</span><span class="underBusiness"><br>No post</span></p></div>
        </div>
@endif
此查询将从数据库中获取一条记录,因此每个循环都不需要

现在,如果您仍然在尝试获取非对象的属性时遇到错误

然后将
$Sport\u Post
变量转换为object,或者尝试以
数组的形式访问该值,以获取非object的属性“image”-完整错误您可以在blade文件中转储$Sport\u Post变量并共享结果吗?无需调用
All()
这就足够了
$Sport\u Post=\App\Post::where('category_id','=',3)->first();
在这里调用
get()
$Sport_Posts=\App\Post::where('category_id','=',3)->skip(1)->get();
仍然没有全部错误。我不知道。我的phpmyadmin中有4篇帖子。
$Sport_Post = \App\Post::Where('category_id','=',3)->first();