Class not found
-
hello All
im trying to create a package with controller and model but it seems the controller is not reconize the model ?
even though i setup namespace correctly
namespace packages\Drov\Address\Models; use Illuminate\Database\Eloquent\Model; class Area extends Model { // }
<?php namespace Drov\Address\Http\Controllers; use Illuminate\Http\Request; use packages\Drov\Address\Models\Area;
Route::post('address/area/save','Drov\Address\Http\Controllers\AddressController@store')->name('area.save');
please advise
Best regards
-
Hello,
Please run -
composer dump-autoload
command then check and make sure that you have used proper namespace.
-
i already did it
do i have to write the whole path
like
namespace packages\Drov\src\Address\Models;
Or
namespace packages\Drov\Address\Models;
do we write 'src' ?
Best regards
-
Don' need to add src, second one is right.
-
Dear @rahul
thats what i did still showing me class not found ?
namespace Drov\Address\Http\Controllers; use Illuminate\Http\Request; use packages\Drov\Address\Models\Area;
<?php namespace packages\Drov\Address\Models; use Illuminate\Database\Eloquent\Model; class Area extends Model { // }
is there another solution ?
i did create the model manually not using php artisan does that cause not to work ?
only the migration file i did it with php artisan
Please advise ?
Best regards
-
You have used wrong namespace.
Did your model is present like (Directory structure) -
Packages->Drov->Address->Models->Area.
Is that directory structure for your model.
Thanks
-
Dear @rahul
yes that is correct , the error shows the
<?php namespace Drov\Address\Http\Controllers; use Illuminate\Http\Request; use packages\Drov\Address\Models\Area; // when you want to use the model you put the whole path correct ?
the error is from the AreaController where it cant see the model
the full path to Area.php model
packages/Drov/Address/src/Models
best regards
-
i have to insert Area in order to use it
$area = new Area();
-
-
/Area
where do you mean ?
use packages\Drov\Address\Models\Area; // like this use packages/Drov/Address/Models/Area; // it does not. work error
-
-
-
Hello @cmpengineers
Push your code on git hub or git lab, and add me.
I need to check. -
Dear @rahul
finally its working i only needed to add App\
use App\packages\Drov\src\Models\Area;
Best regards
-
Dear @rahul
use App\packages\Drov\src\Models\Area; // this is the one that is working
i really appreciate it your effort
Best regards
-
This post is deleted!