Laravel add ads to web

  ads, laravel, php

i have web and i want to add 4 banners on it and when user will click on it i want to count how many clicks it will have
and controller them with admin/voyager

i created table

  $table->text('view')->nullable();
  $table->integer('top')->nullable();
  $table->integer('right')->nullable();
  $table->integer('bottom')->nullable();
  $table->integer('left')->nullable();

Ads model

 public static function top()
    {
        return self::where('top', '1')->first();
    }

    public static function right()
    {
        return self::where('right', '1')->first();
    }

    public static function bottom()
    {
        return self::where('bottom', '1')->first();
    }


    public static function left()
    {
        return self::where('left', '1')->first();
    }

and i add in helper.php

function ad_exists($location){
    try {
     return !! Ads::$location();
    } catch(Exception $e){
        return false;
    }
}

function ad($location){
    if(ad_exists($location)){
        return Ads::$location();
    } else {
        return null;
    }

 <img class="" src="{{Storage::url(ad('right')->image)}}" alt="">

and i add in seeder imgs and its shows imgs on web but when i’m trying to add new banner in voyager its errors me

AppModelsAds::top must return a relationship instance.

so i don’t really know how to do all of this i’m new in programming

is there any examples for making ads on web?

Source: Laravel

Leave a Reply