Laravel 5: не удается найти класс в контроллере, в контроллере указано «use App / Something»

Я был бы признателен за помощь в определении того, что не так, я смотрел на это в течение нескольких часов.

local.ERROR: исключение ‘Symfony \ Component \ Debug \ Exception \ FatalErrorException’ с сообщением ‘Class’ App \ Http \ Controllers \ App \ Type ‘Type’ not found ‘в C: \ wamp \ www \ Website \ app \ Http \ Controllers \ TripController.php: 35.

Контроллер выглядит следующим образом:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Trip;
use App\Type;
use DB;

class TripController extends Controller
{
/**
* Display a listing of the resource.
*
* @return Response
*/

public function newTrip(Request $request)
{

//The sent info
$placeTypes = $request -> input('placeTypeString');
$user = $request -> input('id');
$placeTypesArrays = $request -> input('searchTypesCollectionArray');

//upload trip
Trip::create(['user_id' => $user, 'trip_type' => $placeTypes]);


//associate Trip with its types
$lastInsertedTripId = DB::table('trips')->orderBy('created_at', 'desc')->first();
$types = App\Type::all();


foreach ($placeTypesArrays as $arrayEntry)
{

foreach ($types as $type)
{
$typeName = $type->name;

if($typeName==$arrayEntry)
{
$Types->propertyOf()->attach($trip_id);
}
}

}

//upload
Trip::create(['user_id' => $user, 'trip_type' => $placeTypes]);

}






//     //returns all posts in an app friendly manner
// public function indexJson()
// {
//     //cache the search
//     $result= Cache::remember("reply",1,function()
//     {


//          $posts = Post::orderBy('created_at', 'desc')->get()->first();
//          return $posts;

//     });

//     return $result;

// }




public function index()
{
//
}

/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param  Request  $request
* @return Response
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*
* @param  int  $id
* @return Response
*/
public function show($id)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param  int  $id
* @return Response
*/
public function edit($id)
{
//
}

/**
* Update the specified resource in storage.
*
* @param  Request  $request
* @param  int  $id
* @return Response
*/
public function update(Request $request, $id)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param  int  $id
* @return Response
*/
public function destroy($id)
{
//
}
}

Модель написана следующим образом:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use App\Trip;

class Type extends Model
{
//
public function propertyOf()
{
return $this->belongsToMany('App\Trip');
}

}

0

Решение

Вам нужно либо использовать \ App \ Тип или же Тип. Первый — полное имя класса, второй — класс, который вы импортировали вместе с вашим использование заявление. Когда вы делаете App \ Тип, который не является ни именем класса, ни полностью определенным именем класса, PHP ищет класс в текущем пространстве имен.

замещать

$types = App\Type::all();

с

$types = Type::all();
0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector