【发布时间】:2020-12-04 14:43:43
【问题描述】:
在 pma "ogsett" 中有一个表,你需要在其中选择一行。 在模型中,Ogsett 指出了使用哪个表。 在控制器(ServiceController)中我指出了以下代码
<?php
namespace App\Http\Controllers;
use App\Service;
use App\Ogsett;
use Illuminate\Http\Request;
class ServiceController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$og = Ogsett::wherePages('service');
return view('price.main', compact('og'));
}
在页面上,我是这样显示的
@foreach($og as $seo_item)
{{ $seo_item->title }}
@endforeach
在其中,我参考了这张表,并选择了带有值标题的字段 - 服务。 但是我的数据没有显示在页面上。
底座本身是这样的
=======================================================
|ID|PAGES| TITLE|DESCRIPTION|URL|IMAGES|LOCAL|SITE_NAME|
=======================================================
| 1|service|TitlePage|DescPage Service|service|images.jpg|en|localhost|
| 2|contact|ContactPage|DescPage Contact|conatact|images.jpg|en|localhost|
我哪里做错了?
【问题讨论】:
-
使用
$og = Ogsett::wherePages('service')->firstOrFail();
标签: php mysql laravel select line