xheinrich/adsense-ads

在Laravel中轻松展示Adsense广告。

v0.1.4 2017-02-04 12:56 UTC

This package is auto-updated.

Last update: 2024-09-20 16:22:33 UTC


README

License Latest Stable Version Total Downloads

这是一个Laravel 5的包,用于轻松包含Adsense广告单元。

安装

在项目根目录下运行

composer require mastergalen/adsense-ads

设置配置文件

运行 php artisan config:publish mastergalen/adsense-ads

编辑生成的配置文件 /config/ads.php 以添加您的广告单元

return [
    'client_id' => 'YOUR_CLIENT_ID', //Your Adsense client ID e.g. ca-pub-9508939161510421
    'ads' => [
        'responsive' => [
            'ad_unit_id' => 12345678901,
            'ad_format' => 'auto'
        ],
        'rectangle' => [
            'ad_unit_id' => 1234567890,
            'ad_style' => 'display:inline-block;width:300px;height:250px',
            'ad_format' => 'auto'
        ]
    ]
];

使用Laravel注册包

在您的 config/app.php 文件的 providers 数组中添加提供者

Mastergalen\AdsenseAds\AdsServiceProvider::class,

注册别名

'Ads' => Mastergalen\AdsenseAds\AdsFacade::class,

用法

要在blade模板中显示广告,只需使用 {!! Ads::show('responsive') !!} ,例如。