我将API从Laravel 5.6迁移到Lumen 5.6
我的应用使用了我的插件,引用了Illuminate\Foundation\Auth\User
但是Lumen似乎没有。这是正常的吗?
(1/1) Error
Class 'Illuminate\Foundation\Auth\User' not found
in HasRelationships.php line 656
at Model->newRelatedInstance('Illuminate\\Foundation\\Auth\\User')
in HasRelationships.php line 418
at Model->belongsToMany('Illuminate\\Foundation\\Auth\\User', 'competitor', 'championship_id')
in Championship.php line 87
at Championship->users()
in Builder.php line 546
at Builder->Illuminate\Database\Eloquent\{closure}()
at call_user_func(object(Closure))
in Relation.php line 89
at Relation::noConstraints(object(Closure))
in Builder.php line 550
at Builder->getRelation('users')
in Builder.php line 518
at Builder->eagerLoadRelation(array(object(Championship), object(Championship), object(Championship), object(Championship)), 'users', object(Closure))
in Builder.php line 498
at Builder->eagerLoadRelations(array(object(Championship), object(Championship), object(Championship), object(Championship)))
in Builder.php line 466
at Builder->get(array('*'))
in Relation.php line 154
at Relation->get()
in Relation.php line 143
at Relation->getEager()
in Builder.php line 529
at Builder->eagerLoadRelation(array(object(Tournament)), 'championships', object(Closure))
in Builder.php line 498
at Builder->eagerLoadRelations(array(object(Tournament)))
in Builder.php line 466
at Builder->get(array('*'))
in BuildsQueries.php line 77
at Builder->first()
in CompetitorController.php line 35
at CompetitorController->index('fake-tournoi')
at call_user_func_array(array(object(CompetitorController), 'index'), array('fake-tournoi'))
in BoundMethod.php line 29
at BoundMethod::Illuminate\Container\{closure}()
in BoundMethod.php line 87
at BoundMethod::callBoundMethod(object(Application), array(object(CompetitorController), 'index'), object(Closure))
in BoundMethod.php line 31
at BoundMethod::call(object(Application), array(object(CompetitorController), 'index'), array('slug' => 'fake-tournoi'), null)
in Container.php line 564
at Container->call(array(object(CompetitorController), 'index'), array('slug' => 'fake-tournoi'))
in RoutesRequests.php line 373
at Application->callControllerCallable(array(object(CompetitorController), 'index'), array('slug' => 'fake-tournoi'))
in RoutesRequests.php line 339
at Application->callLumenController(object(CompetitorController), 'index', array(1, array('uses' => 'App\\Http\\Controllers\\CompetitorController@index'), array('slug' => 'fake-tournoi')))
in RoutesRequests.php line 313
at Application->callControllerAction(array(1, array('uses' => 'App\\Http\\Controllers\\CompetitorController@index'), array('slug' => 'fake-tournoi')))
in RoutesRequests.php line 275
at Application->callActionOnArrayBasedRoute(array(1, array('uses' => 'App\\Http\\Controllers\\CompetitorController@index'), array('slug' => 'fake-tournoi')))
in RoutesRequests.php line 260
at Application->handleFoundRoute(array(1, array('uses' => 'App\\Http\\Controllers\\CompetitorController@index'), array('slug' => 'fake-tournoi')))
in RoutesRequests.php line 230
at Application->handleDispatcherResponse(array(1, array('uses' => 'App\\Http\\Controllers\\CompetitorController@index'), array('slug' => 'fake-tournoi')))
in RoutesRequests.php line 164
at Application->Laravel\Lumen\Concerns\{closure}(object(Request))
at call_user_func(object(Closure), object(Request))
in Pipeline.php line 52
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request))
in InjectDebugbar.php line 65
at InjectDebugbar->handle(object(Request), object(Closure))
in Pipeline.php line 151
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request))
in Pipeline.php line 32
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request))
in CorsMiddleware.php line 18
at CorsMiddleware->handle(object(Request), object(Closure))
in Pipeline.php line 151
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request))
in Pipeline.php line 32
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request))
in Pipeline.php line 104
at Pipeline->then(object(Closure))
in RoutesRequests.php line 410
at Application->sendThroughPipeline(array('App\\Http\\Middleware\\CorsMiddleware', 'Barryvdh\\Debugbar\\Middleware\\InjectDebugbar'), object(Closure))
in RoutesRequests.php line 166
at Application->dispatch(null)
in RoutesRequests.php line 107
at Application->run()
in index.php line 28
at require('/Users/julien/Documents/Proyectos/kz-api/public/index.php')
in server.php line 147
编辑:
use Illuminate\Foundation\Auth\User;
...
public function users()
{
return $this->belongsToMany(User::class, 'competitor', 'championship_id')
->withPivot('confirmed')
->withTimestamps();
}
如果我更改Illuminate\Foundation\Auth\User
App\User
,它会有效,但由于此代码属于插件,因此建议永远不要引用App\User
,因为您永远不知道命名空间它将运行的项目
答案 0 :(得分:0)
是的,这很正常。 laravel/lumen-framework
laravel/framework
不会引入Illuminate
中的Illuminate\Foundation
子模块,而public Color generateRandomColor(Color mix) {
Random random = new Random();
int red = random.nextInt(256);
int green = random.nextInt(256);
int blue = random.nextInt(256);
// mix the color
if (mix != null) {
red = (red + mix.getRed()) / 2;
green = (green + mix.getGreen()) / 2;
blue = (blue + mix.getBlue()) / 2;
}
Color color = new Color(red, green, blue);
return color;
}
中的子模块不包括 void color() {
float red = (random(256));
float green = (random(256));
float blue = (random(256));
}
if (mix != null){
red = (red + mix.getREd())/2;
green = (green + mix.getGreen())/2;
blue = (blue + mixgetBlue())/2;
}
color (red,gree,blue)
中的内容。