简体   繁体   中英

Laravel: Target [...] is not instantiable when building [...]

I see there are a lot of questions on Stackoverflow like this, but they all seem to have different unrelated answers, so hear me out:
I'm updating an old Laravel app's file structure to that of the newest version (8.x) and I am getting this error when I visit the the / route: Error + Stack trace

Illuminate\Contracts\Container\BindingResolutionException
Target [Illuminate\View\ViewFinderInterface] is not instantiable while building [App\Http\Controllers\HomeController, App\Lib\Services\Rendering\HomepageRenderer, Illuminate\View\Environment].

I'm not sure what this even means.
Here is the code for the HomeController :

<?php

namespace App\Http\Controllers;
use App\Lib\Services\Mail\Mailer;
use App\Lib\Services\Validation\ContactValidator;
use App\Lib\Services\Rendering\HomepageRenderer;

use App;
use Illuminate\View\View;
use Input;
use Redirect;

use App\Http\Controllers\Controller;


class HomeController extends Controller
{
    /**
     * Validator instance.
     * 
     * @var Lib\Services\Validation\ContactValidator
     */
    private $validator;

    /**
     * Options instance.
     * 
     * @var Lib\Services\Options\Options
     */
    private $options;

    /**
     * Mailer instance.
     * 
     * @var Lib\Services\Mail\Mailer;
     */
    private $mailer;


    public function __construct(ContactValidator $validator, Mailer $mailer, HomepageRenderer $renderer)
    {
        $this->mailer = $mailer;
        $this->renderer = $renderer;
        $this->validator = $validator;
        $this->options = App::make('options');

        $this->beforeFilter('logged', array('only' => array('createreview')));
    }

    /**
     * Show homepage.
     * 
     * @return View
     */
    public function index()
    {   
        return $this->renderer->render('Home.Home')->withCleantitle("Newest Reviews");  
    }

    /**
     * Show contact us page.
     * 
     * @return View
     */
    public function contact()
    {
        return View::make('Main.Contact');
    }

    public function createreview()
    {
        return View::make('Reviews.Create')->withCleantitle("Post Your Review");
    }

    /**
     * Sends an email message from contact us form.
     * 
     * @return View
     */
    public function submitContact()
    {
        $input = Input::all();

        if ( ! $this->validator->with($input)->passes())
        {
            return Redirect::back()->withErrors($this->validator->errors())->withInput($input);
        }

        $this->mailer->sendContactUs($input);

        return Redirect::to('/')->withSuccess( trans('main.contact succes') );
    }
}

What does the error mean and what can I do to resolve it?
Thanks.

Wouldn't using view('Home.Home') be sufficient?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM