2016-08-16 131 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()); 
    }); 

}