s@jj@d
2 سال پیش توسط s@jj@d مطرح شد
2 پاسخ

اینترفیس در لاراول

سلام وقت بخیر بنده یک اینترفیس و ریپازیتوری توی پروژه ران کردم و به ریجیستر هم معرفی کردم وهنوز بهم target class میزنه که فلان کلاس وجود نداره

اینم نمونه کدم

کد خود را اینج
class EloquentRepository implements BannerRepositoryInterface
{
public function store($request)
{
// TODO: Implement store() method.
}
public function paginate($data)
{
// TODO: Implement paginate() method.
}
public function update($request, $id)
{
// TODO: Implement update() method.
}
public function show($where, $select)
{
// TODO: Implement show() method.
}
public function all($select = '*')
{
// TODO: Implement all() method.
}
}
ا وارد کنید

اینم از اینترفیسم

<?php
namespace App\Repositories;
interface BannerRepositoryInterface
{
public function store($request);
public function paginate($data);
public function update($request,$id);
public function show($where,$select);
public function all($select='*');
}

اینم از پروایدرم

&lt;?php
namespace App\\Providers;
use Illuminate\\Support\\ServiceProvider;
use app\\Repositories\\EloquentRepository;
use app\\Repositories\\BannerRepositoryInterface;
class AllProviderInterface extends ServiceProvider
{
/\*\*
- Register services.
-
- @return void
\*/
public function register()
{
$this-&gt;app-&gt;bind(
BannerRepositoryInterface::class,
EloquentRepository::class
);
}
/\*\*
- Bootstrap services.
-
- @return void
\*/
public function boot()
{
//
}
}

ارورم اینه

"status": "error",
"message": "Target class [app\\Repositories\\EloquentRepository] does not exist.",
"data": null

php
تگ‌های محبوب
ثبت پرسش جدید
مهدی نظری
تخصص : توسعه دهنده Front End
@mahdi.nazari 2 سال پیش مطرح شد
0

سلام دوست من 🖐
امیدوارم حالت خوب و عالی باشی✨

با توجه به اطلاعاتی شما ، مشکل اصلی در (namespace) در کدت وجود داره . در کد‌هایی که گذاشتی ، تو از نام فضای نامی app\\Repositories استفاده کردی ، اما باید از App\Repositories استفاده کنی.

برای رفع این مشکل، کافیه تغییرات زیر را انجام بدی :

در کد EloquentRepository:

use App\Repositories\BannerRepositoryInterface;
class EloquentRepository implements BannerRepositoryInterface
{
// ...
}

در پروایدر AllProviderInterface:

use App\Repositories\BannerRepositoryInterface;
use App\Repositories\EloquentRepository;
class AllProviderInterface extends ServiceProvider
{
public function register()
{
$this->app->bind(
BannerRepositoryInterface::class,
EloquentRepository::class
);
}
// ...
}

همچنین چک کن که نام فضای App\Repositories در فایل هات به درستی تعیین شده باشن و تایپ‌ها و حروف بزرگ و کوچک را به درستی تطابق دادی . این تغییرات باید مشکل "Target class does not exist" را رفع کنه.

امیدوارم پاسخم بهت کمک کرده باشه ❤️
موفق و پیروز باشی 🤘🌹


s@jj@d
@khaledi.sajjad20502050 2 سال پیش مطرح شد
0

کسی هست کمک کنه


مهدی نظری
تخصص : توسعه دهنده Front End
@mahdi.nazari 2 سال پیش مطرح شد
0

سلام دوست من 🖐
امیدوارم حالت خوب و عالی باشی✨

با توجه به اطلاعاتی شما ، مشکل اصلی در (namespace) در کدت وجود داره . در کد‌هایی که گذاشتی ، تو از نام فضای نامی app\\Repositories استفاده کردی ، اما باید از App\Repositories استفاده کنی.

برای رفع این مشکل، کافیه تغییرات زیر را انجام بدی :

در کد EloquentRepository:

use App\Repositories\BannerRepositoryInterface;
class EloquentRepository implements BannerRepositoryInterface
{
// ...
}

در پروایدر AllProviderInterface:

use App\Repositories\BannerRepositoryInterface;
use App\Repositories\EloquentRepository;
class AllProviderInterface extends ServiceProvider
{
public function register()
{
$this->app->bind(
BannerRepositoryInterface::class,
EloquentRepository::class
);
}
// ...
}

همچنین چک کن که نام فضای App\Repositories در فایل هات به درستی تعیین شده باشن و تایپ‌ها و حروف بزرگ و کوچک را به درستی تطابق دادی . این تغییرات باید مشکل "Target class does not exist" را رفع کنه.

امیدوارم پاسخم بهت کمک کرده باشه ❤️
موفق و پیروز باشی 🤘🌹


برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام