Русское сообщество разработки на PHP-фреймворке Laravel.
Ты не вошёл. Вход тут.
Страницы 1
Здравствуйте!
У меня такая проблема - не найден CharacterController
Illuminate\Contracts\Container\BindingResolutionException: Target class [CharacterController] does not exist. in file C:\Users\HP\Desktop\RS\OSPanel\domains\rick_and_morty_backen d\vendor\laravel\framework\src\Illuminate\Container\Containe r.php on line 875
Текст контроллера:
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades;
use Illuminate\Support\Facades\App;
use Illuminate\Http\Request;
use App\Models\Character;
class CharacterController extends Controller
{
function characters()
{
$characters = Character::orderBy('name')->get();
return response()->json($characters);
}
}
Ошибка возникает в api.php:
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\CharacterController;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
//Route::resource('/v1/characters', '\App\Http\Controllers\CharacterController');
Route::resource('/v1/characters', 'CharacterController');
Если здесь
//Route::resource('/v1/characters', '\App\Http\Controllers\CharacterController');
убрать комментарий - сообщения, что класс контроллера не найден, нет.
Не в сети
Вопрос решен:
Route :: resource( '/v1/characters', CharacterController :: class );
Не в сети
Страницы 1