How to implement google ad-sense with laravel application?

I am trying to develop an application where user will be able to upload and share video. And on the video page I'll be able to show ads.I have literally no idea how to do that. o I have completed everything except the ad part. And also I don't wanna show more than 3 ads on my video page.

ilinovster replied 3 months ago
Elena Gilbert replied 3 months ago

No, I don't think this package( ) does any extra task, it just use the google-.api-client-library. I think you can directly use the google-api-client-library. Also one more thing I would like to point out to you is that if you use outh2 then everytime you want to access adsense data, you will have to allow the application permission manually. I know this is not so good, but what to do this is how google adsense api works. Thank you.

Nine Hertz replied 3 months ago

A convenient way to display Google AdSense ads in your Laravel 5 application. Just setup your ads, then $adsense->get('ad') to return the HTML for the ad.


Install via composer. Publish configuration files. Add your ads.


Edit your composer.json file:

"require": { "ardyn/adsense": "~2.0" } Run composer update.

Publish Configuration Files

Run php artisan vendor:publish, then modify the contents of /config/adsense.php.

id required The ad ID.

size required Size of ad. Either an array or string.

description A short description of the ad.

type Either Ad::LINK or Ad::CONTENT. Default is Ad::CONTENT.

return [

'ads' => [

'example' => [

  'id' => '123456789',

  'size' => [ 300, 100 ],

  'description' => 'Test Ad',

  'type' => Ad::CONTENT,




Refer to adsense.php for more configuration documentation.

Integrate with Laravel 5

Add the following to the providers array in your config/app.php file:

'Ardyn\Adsense\AdsenseServiceProvider' And add the alias in aliases array:

'Adsense' => 'Ardyn\Adsense\Facades\Adsense'


To display the HTML for an ad, call Adsense::get('example'); where 'example' is the array index of your ad.

Determine whether ads are displayed by setting the enabled configuration value to either a boolean value or a closure that returns a boolean value. The closure may include parameters. Pass the arguments in Adsense::get('example', [ /* parameters */ ]). Closures are not recommened as Laravel's config:cache cannot serialize closures correctly.

Laravel Web Developers

Dedicated PHP Web Programmers

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us