Laravel 5:无法在控制器中找到课程,并使用App / Something'在控制器中说明

时间:2015-08-22 13:29:34

标签: php laravel laravel-5 classnotfound

我希望得到一些帮助来确定我已经盯着这几个小时的错误。

  

local.ERROR:exception' Symfony \ Component \ Debug \ Exception \ FatalErrorException'消息' Class' App \ Http \ Controllers \ App \ Type'找不到'在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');
    }

}

1 个答案:

答案 0 :(得分:0)

您需要使用 \ App \ Type 键入。第一个是完全限定的类名,第二个是使用 use 语句导入的类。当您执行 App \ Type 时,它既不是类名也不是完全限定的类名,PHP正在查找当前命名空间中的类。

替换

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

$types = Type::all();