Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous class resolution in laravel phpexcel update

I try to update the laravel with php excel while installing i found the below warning in the composer.

Error:

Warning: Ambiguous class resolution, "SettingsController" was found in both 

"C:\xampp\htdocs\mti\app\controllers\SettingsController.php" and 

"C:\xampp\htdocs\mti\app\controllers\SettingsControllerBackup.php", the first 

will be used.Warning: Ambiguous class resolution, "ClassModel" was found in both

"C:\xampp\htdocs\mti\app\models\ClassModel.php" and "C:\xampp\htdocs\mti\

app\models\LoginModel.php", the first will be used.

SettingsController:

<?php

class SettingsController extends BaseController
{

    public function ChangePasswordLayout()
    {
        return View::make('settings/changepassword/changepassword');
    }

    public function ChangePasswordProcess()
    {
        $PasswordData = Input::all();

        Validator::extend('pwdvalidation', function($field, $value, $parameters)
        {
            return Hash::check($value, Auth::user()->password);
        });

        $messages = array('pwdvalidation' => 'The Old Password is Incorrect');

        $validator = Validator::make($PasswordData, User::$rulespwd, $messages);
        if ($validator->passes()) 
        {
            $user = User::find(Auth::user()->id);
            $user->password = Hash::make(Input::get('NewPassword'));
            $user->save();
            return Redirect::to('changepassword')->withInput()->with('Messages', 'The Password Information was Updated');
        } else 
        {
            return Redirect::to('changepassword')->withInput()->withErrors($validator);
        }

    }

    public function ProfileLayout()
    {
        $user = Auth::user()->id;
        $ProfileDetailsbyid = ProfileModel::where('id', $user)->get()->toArray();   
        return View::make('settings/profile/profile')->with('ProfileDetailsbyid', $ProfileDetailsbyid);
    }

    public function ProfileUpdateProcess($data=NULL)
    {

    $user = Auth::user()->id;
    $ProfileDetailsbyid = ProfileModel::where('id', $user)->get()->toArray();

        $ProfileData = array_filter(Input::except(array('_token')));

      $validation  = Validator::make($ProfileData, ProfileModel::$rules);        
        if ($validation->passes()) 
        {

        if(!empty($ProfileData['Photo']))
    {
    Input::file('Photo')->move('assets/uploads/profilephoto/', $user . '-Photo.' . Input::file('Photo')->getClientOriginalName());
    $Photo=$user.'-Photo.' . Input::file('Photo')->getClientOriginalName();
    unset($ProfileData['Photo']);
    $ProfileData['Photo']=$Photo;
    }

           $affectedRows = ProfileModel::where('id', $user)->update($ProfileData);
            //VehicleModel::create($VehicleData);
            return Redirect::to('profile')->with('Message', 'Profile Details Update Succesfully')->with('ProfileDetailsbyid', $ProfileDetailsbyid);
        } else 
        {

            return Redirect::to('profile')->withInput()->withErrors($validation->messages())->with('ProfileDetailsbyid', $ProfileDetailsbyid);
        }
    }


}

ClassModel:

<?php
class ClassModel extends Eloquent
{

    protected $primaryKey = 'AutoID';
    protected $created_at = 'CreatedAt';
    protected $updated_at = 'UpdatedAt';
    protected $table = 'class';
    protected $guarded = array('GradeName');
    protected $fillable = array('GradeName');

    public function batch(){
        return $this->hasMany('BatchModel', 'Class');
    }

    public function studentadmissionresult(){
        return $this->hasMany('StudentAdmissionModel', 'StudentCourse');
    }

    public $timestamps = true;



    public static $rules = array(
        'GradeName' =>  array('required', 'unique:class','regex:/^./'),
        'GradeSection' => 'required',
        'GradeCode' => array('required', 'unique:class')
                             );
     public static $updaterules = array(
        'GradeName' =>  array('required','regex:/^./'),
        'GradeSection' => 'required',
        'GradeCode' => array('required')
                             );                      

}

I following this tutorial:

https://github.com/Maatwebsite/Laravel-Excel

I have try following command :

composer require maatwebsite/excel": "~1.2.1
like image 972
Deenadhayalan Manoharan Avatar asked Jan 14 '15 06:01

Deenadhayalan Manoharan


1 Answers

This actually has nothing to do with the package you are installing.

Explanation

When recreating the autoload files (composer dump-autoload) after the update Composer detected that you have two classes with the exact same name (but in different files).

Class SettingsController in SettingsController.php and SettingsControllerBackup.php

and class ClassModel in ClassModel.php and LoginModel.php

Composer will then choose to use one of the two (I'm not sure how it makes that decision, it's probably just the first one it finds) and will ignore the other occurrence. - Confirmed. Composer uses first match.

Solutions

  1. Delete the files if you don't need them
  2. Rename the class

A good and common practice is to name the class like the file. This is a simple way to avoid such collisions because two files in the same directory can't have the same name.

like image 98
lukasgeiter Avatar answered Oct 16 '22 04:10

lukasgeiter