Reputation: 15
There is a table in pma "ogsett", you need to select one line in it. In the model, Ogsett indicated which table to work with. In the controller (ServiceController) I indicated the following code
<?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'));
}
On the page, I display it like this
@foreach($og as $seo_item)
{{ $seo_item->title }}
@endforeach
In it, I refer to this table, and select the field with the value title - service. But my data is not displayed on the page.
The base itself looks like this
=======================================================
|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|
Where did I go wrong?
Upvotes: 0
Views: 24
Reputation: 87
If you want to iterate over all the titles you will have to do this
$og = Ogsett::wherePages('service')->get();
and then in your blade
@foreach($og as $seo_item)
{{ $seo_item->title }}
@endforeach
Alternatively you could also use if you only want the title and do not require the other db cols
$og = Ogsett::wherePages('service')->pluck('title');
and then on the blade you can
@foreach($og as $seo_item)
{{ $seo_item }}
@endforeach
Upvotes: 1