2016-08-16 134 views
-1

环顾四周后,我还没有找到我正在寻找的东西,所以我在这里。Laravel变量在og:标签

有没有办法从你的数据库中设置facebook的og:tags变量?

我使用的是Laravel 5.2,我有一个app.blade和我的html模板,我在这里调用@section('content')来显示每个特定的页面。

在app.blade(母版页)我有这样的代码

<meta property="og:url"   content="@yield('url')" /> 
<meta property="og:type"   content="@yield('type')" /> 
<meta property="og:title"   content="@yield('ogtitle')" /> 
<meta property="og:description" content="@yield('description')" /> 
<meta property="og:image"   content="@yield('image')" /> 

我每天都给特定页面像这样的参数设置:

@section('url', Request::fullUrl()) 
@section('image', 'http://www.myurl.eu/img/share.jpg') 
@section('type', 'article') 
@section('ogtitle', 'Title | Careers') 
@section('description', 'My personal website title') 

现在我已经在我的网站节myurl.eu/careers其中我有几个详细信息页面,为每个打开的工作位置。现在我想将我的数据库中的变量设置为og:titleog:description

尝试这个(下面)没有提取任何东西(所以共享是空白)调试后,并刮了几次facebook tool

@section('description', $job->description) 

@section('description', {{$job->description}}) 

感谢

回答

1

首先,你必须相关的数据分享给你的意见,如果你想在所有视图meta标签,然后做这样的事情:

<html prefix="og: http://ogp.me/ns#"> 
<head> 
<title>The Tittle </title> 

<meta property="og:title" content="{{ $data->title}}" /> 
<meta property="og:type" content="article" /> 
<meta property="og:description" content="{{ $data->description}}" /> 
<meta property="og:url" content="{{ $data->page_url}}" /> 
<meta property="og:image" content="{{ $data->imag_url}}" /> 
... 
</head> 
+0

如果我用这个方法,我必须设置在我的母版中的数据,一旦定义它。我想这是每一个页面(工作)不同的,但现在我需要它将充满来自数据库的数据(不起作用)。 – nclsvh

+0

将您的数据分享到来自数据库的视图。 – Rastagar

+0

您如何将每个视图的不同数据分享给1个主页?你将如何定义$数据和在哪里? – nclsvh

0

我这样做。 (具体数据各方意见)

public function boot() 
    { 
//  $notifyDate = $date->addDays(-3); 
    view()->composer('partials.header', function($view) 
    { 
     $date = Carbon::now(); 
     $notifyDate = $date->addDays(3); 
     $view->with('notify', DB::table('purchases') 
      ->join('stock_item', 'stock_item.stm_id','=','purchases.item_id') 
      ->join('brands', 'brands.bid','=','purchases.brand_id') 
      ->join('categories', 'categories.cat_id','=','purchases.category_id') 
      ->select('purchases.*','stock_item.item_name','brands.brand_name','categories.category_name') 
      ->where('purchases.expire_date', '<=', $notifyDate) 
      ->where('check_exp', 0)->get()); 
    }); 

}