0
votes

I’m new to Laravel 5. I tried to create Customer model in my Models folder. I created both CustomerController and Customer via php artisan make:... and now I get the error:

FatalErrorException in CustomerController.php line 30: Class 'App\Http\Controllers\Cusomter' not found.

My Customer model:

<?php namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Customer extends Model {

   //
    protected $table = 'Customer';
    protected $primaryKey = 'CID';

   // protected $fillable = [
  //    'Name',
  //    'Gender',
  //    'Address',
  //    'DiscountPercent',
  //    'Email',
  //    'Phone'
  // ];

}

My CustomerController:

<?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

use App\Models\Customer;

class CustomerController extends Controller {

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        //
        $customers = Customer::all();
        return View::make('Customer.home',compact('customers'));
        // return View('Customer.home');
    }

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

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

    /**
     * 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  int  $id
     * @return Response
     */
    public function update($id)
    {
        //
    }

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

}

I dont know what i was doing anything wrong. Is there any help. I also did some search on Internet and i know its about namespace. Is there any ebook or documents for me to understand how namespace works, how to use and do i need to declare before using it

2
yes i did move this Customer.php to Models folder. i still keep two Customer.php files. One in app\Models and one in appuser1610851
If they both have the namespace same namespace (App\Models) that might be the problem...lukasgeiter
thanks for reminding me. i remove the Customer in appuser1610851
And? did it help? (try running composer dump-autoload again after deleting)lukasgeiter
yes i did. but its still stuckuser1610851

2 Answers

0
votes

You’ve spelt “Customer” wrong in your index action.

-2
votes

You should add autoload classmap in composer.json

"autoload": {
    "classmap": [
        "database",
        "app/Models"
    ],
    "psr-4": {
        "App\\": "app/"
    }
},

update composer