Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target [Illuminate\Contracts\View\Factory] is not instantiable. #14

Closed
piyushs3001 opened this issue Nov 9, 2023 · 2 comments
Closed
Assignees
Labels
invalid This doesn't seem right

Comments

@piyushs3001
Copy link

piyushs3001 commented Nov 9, 2023

// SiteController

public function actionAbout()
    {
        return view('pages.about');
    }

i try to inegrate Yii in my laravel project i follow all your steps still it will give me this error

Illuminate\Contracts\Container\BindingResolutionException
Target [Illuminate\Contracts\View\Factory] is not instantiable.

// config/app.php

'providers' => ServiceProvider::defaultProviders()->merge([
    /*
     * Package Service Providers...
     */
    

    /*
     * Application Service Providers...
     */
    Illuminate\View\ViewServiceProvider::class,
    App\Providers\AppServiceProvider::class,
    App\Providers\AuthServiceProvider::class,
    // App\Providers\BroadcastServiceProvider::class,
    App\Providers\EventServiceProvider::class,
    App\Providers\RouteServiceProvider::class,
])->toArray(),

// app/providers/AppServiceProvider.php

use App\Services\MailChimp;
use App\Services\SubscriptionManager;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
    */
    public function register(): void
    {
        $this->app->singleton(MailChimp::class, function ($app) {
            $component = new MailChimp();
            $component->apiKey = config('mailchimp.apiKey');
            $component->apiSecret = config('mailchimp.apiSecret');
            return $component;
        });
        
        $this->app->singleton(SubscriptionManager::class, function ($app) {
            $component = new SubscriptionManager();
            $component->trialPeriod = config('subscription.trialPeriod');
            return $component;
        });
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        //
    }
}

please provide me the solution or tell me what mistake i did ? @klimov-paul

@klimov-paul
Copy link
Member

Unable to reproduce.

Following code works fine:

namespace legacy\controllers;

use yii\web\Controller;

class SiteController extends Controller
{
    public function actionBlade()
    {
        return view('welcome');
    }
}

Judging the error message \Illuminate\View\ViewServiceProvider service provided has been registered/booted in your case.

@klimov-paul klimov-paul added the invalid This doesn't seem right label Nov 16, 2023
@klimov-paul klimov-paul self-assigned this Nov 16, 2023
@piyushs3001
Copy link
Author

piyushs3001 commented Nov 17, 2023

i'm using YII2 advance project that have frontend and backend and i use this directory structure

// legacy/frontend/controllers/SiteController.php

namespace frontend\controllers;
use yii\web\Controller;
/**
 * Site controller
 */
class SiteController extends Controller
{
    public function actionAbout()
    {
        return view('pages.about');
    }
}

in this case what i have to do ? @klimov-paul

here is the error

Illuminate\Contracts\Container\BindingResolutionException
Target [Illuminate\Contracts\View\Factory] is not instantiable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants