Class Not Found in Laravel 5

Asked

Viewed 408 times

1

I have this Controller in the Laravel 5.

Homecontroller.php

<?php namespace App\Http\Controllers;

    use View;
    use App\Portfolio;
    use App\Cliente;

    class HomeController extends Controller {

    public function getIndex(){

        # PORTFOLIO - Separado em Três Partes no Owl Carousel
        $portfolio['um']    = Portfolio::take(5)
                              ->whereStatus(1)
                              ->get();

        $portfolio['dois']  = Portfolio::skip(5)
                              ->whereStatus(1)
                              ->take(5)
                              ->get();

        $portfolio['tres']  = Portfolio::skip(10)
                              ->whereStatus(1)
                              ->take(5)
                              ->get();

        return view('frontend.home')
               ->withPortfolio($portfolio);
    }

}

He makes a extends of Controller. And inside that Controller created a function.

<?php namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesCommands;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;

abstract class Controller extends BaseController {

    use DispatchesCommands, ValidatesRequests;

    # Nome do Cliente no Portfolio
    static function NomeCliente($cliente){
        $explode    = explode(' ', $cliente);
        $varCliente = $explode[0].' <span>'.$explode[1].'</span>';

        return $varCliente;
    }

}

View

<h2>{!! Controller::NomeCliente($item->client->nome_fantasia) !!}</h2>

Then in the View I call this function by Controller, like I always did in the Laravel 4.2.

But now this mistake happens:

Class 'Controller' not found

What’s wrong or missing ?


I created a new controller, called Newcontroller.php test only. Even so in the View when I call, it also says that it was not found.


Resolution

I was able to solve it this way:

Placing the complete path of Controller in View. Ex:

{!! App\Http\Controllers\URLController::Link('quem-somos') !!}

  • the Class ta file with the same name as the Class?

  • Yes. I solved the stop. But inside my controller is a Request, which does not work. Gives the following error: Non-static method Illuminate Http Request::segment() should not be called statically

1 answer

1


Resolution

I was able to solve it this way:

Placing the full path of the Controller in the View. Ex:

{!! App\Http\Controllers\URLController::Link('quem-somos') !!}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.