config/app.php
'providers' => [
// ...
App\Providers\ViewServiceProvider::class,
App\Http\View\Composers\AdComposer::class,
],
app/Providers/ViewServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class ViewServiceProvider extends ServiceProvider
{
public function register()
{
//
}
public function boot()
{
View::composer(
'layouts.sidebar', 'App\Http\View\Composers\AdComposer'
);
}
}
app/Http/View/Composers/AdComposer.php
<?php
namespace App\Http\View\Composers;
use App\Ad;
use Illuminate\View\View;
use Illuminate\Support\Facades\Request;
class AdComposer
{
protected $ads;
public function __construct(Ad $ads)
{
$this->ads = $ads;
}
public function compose(View $view)
{
$view->with('ads', $this->ads);
}
}
my problem is:
TypeError Argument 1 passed to App\Http\View\Composers\AdComposer::__construct() must be an instance of App\Ad, instance of Illuminate\Foundation\Application given, called in E:\appoo\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php on line 208
How to resovle this problem and pass $ads to view?