出于某种原因,我收到此错误
Handler.php第131行中的NotFoundHttpException:模型[App \ Modules \ Menus \ Models \ Menu]没有查询结果。
我不应该收到此错误,因为我在仪表板功能中根本没有引用菜单模型。
我完成route:clear
和route:cache
但没有成功。
这是我的CustomersController
namespace App\Modules\Customers\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Modules\Menus\Models\Menu;
use App\Modules\Customers\Models\Customer;
use DB;
use Validator;
Use Mail;
use Auth;
class CustomersController extends Controller
{
public function login(Request $request)
{
$this->validate($request, [
'email' => 'required|email',
'password' => 'required'
]);
if(auth('customer_admin')->attempt(array('email' => $request->input('email'), 'password' => $request->input('password'))))
{
if(auth()->guard('customer_admin')->user()->is_activated == '0')
{
$this->logout();
return back()->with('error', 'Please activate your account.');
}
return redirect()->route('dashboard');
}else{
return back()->with('error', 'Your email/password combination is wrong.');
}
}
public function dashboard()
{
echo "dashboard";
}
}
我的web.php路线
Route::get('/signup', [
'uses' => 'CustomersController@signup',
'as' => 'customer.signup'
]);
Route::post('/signup', [
'uses' => 'CustomersController@postSignup',
'as' => 'post.signup'
]);
Route::get('customer/activation/{token}', [
'uses' => 'CustomersController@customerActivation',
'as' => 'activation',
]);
Route::post('/login', [
'uses' => 'CustomersController@login',
'as' => 'login'
]);
// CUSTOMER LOGIN
Route::get('/dashboard', [
'uses' => 'CustomersController@dashboard',
'as' => 'dashboard'
]);
Route::get('/logout', [
'uses' => 'CustomersController@logout',
'as' => 'logout'
]);
完整堆栈跟踪
in Handler.php line 131
at Handler->prepareException(object(ModelNotFoundException)) in Handler.php
line 109
at Handler->render(object(Request), object(ModelNotFoundException)) in
Handler.php line 47
at Handler->render(object(Request), object(ModelNotFoundException)) in
Pipeline.php line 82
at Pipeline->handleException(object(Request),
object(ModelNotFoundException)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in
Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
VerifyCsrfToken.php line 65
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php
line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in
Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php
line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in
Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php
line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php
line 102
at Pipeline->then(object(Closure)) in Router.php line 561
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php
line 520
at Router->dispatchToRoute(object(Request)) in Router.php line 498
at Router->dispatch(object(Request)) in Kernel.php line 174
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in
Pipeline.php line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
TransformsRequest.php line 30
at TransformsRequest->handle(object(Request), object(Closure)) in
Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
TransformsRequest.php line 30
at TransformsRequest->handle(object(Request), object(Closure)) in
Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
ValidatePostSize.php line 27
at ValidatePostSize->handle(object(Request), object(Closure)) in
Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in
Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php
line 102
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 54
1/2 ModelNotFoundException in Builder.php line 395: No query results for
model [App\Modules\Menus\Models\Menu].
in Builder.php line 395
at Builder->firstOrFail() in OpenController.php line 52
at OpenController->content('dashboard')
at call_user_func_array(array(object(OpenController), 'content'), array('id'
=> 'dashboard')) in Controller.php line 55
at Controller->callAction('content', array('id' => 'dashboard')) in
ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(OpenController),
'content') in Route.php line 204
at Route->runController() in Route.php line 160
at Route->run() in Router.php line 559
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php
line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in
Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
VerifyCsrfToken.php line 65
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php
line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in
Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php
line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in
Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php
line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php
line 102
at Pipeline->then(object(Closure)) in Router.php line 561
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php
line 520
at Router->dispatchToRoute(object(Request)) in Router.php line 498
at Router->dispatch(object(Request)) in Kernel.php line 174
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in
Pipeline.php line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
TransformsRequest.php line 30
at TransformsRequest->handle(object(Request), object(Closure)) in
Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
TransformsRequest.php line 30
at TransformsRequest->handle(object(Request), object(Closure)) in
Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
ValidatePostSize.php line 27
at ValidatePostSize->handle(object(Request), object(Closure)) in
Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in
CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in
Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php
line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php
line 102
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 54
答案 0 :(得分:0)
我明白了:
Route::post('/login', [
'uses' => 'CustomersController@login',
'as' => 'login'
]);
各自如何:
Route::get('/login', [
'uses' => 'CustomersController@loginPage',
'as' => 'page.login'
]);
您还可以在用户点击仪表板路线时将用户重定向到登录路线。
public function dashboard()
{
return redirect("login"); //redirect to login page
}
另外,请将您的使用陈述重新安排到:
use DB;
Use Mail;
use Auth;
use Validator;
use App\Http\Requests;
use Illuminate\Http\Request;
use App\Modules\Menus\Models\Menu;
use App\Http\Controllers\Controller;
use App\Modules\Customers\Models\Customer;
这与你所犯的错误无关,这只是一个很好的做法。我对你的问题的回答是你的路线文件,如上所示。
答案 1 :(得分:0)
我假设您在给定名为Laravel 5.2
web.php
您的路由已加载到RouteServiceProvider
,并假设所有控制器都位于命名空间App\Http\Controllers
下
我注意到你的控制器位于App\Modules\Customers\Http\Controllers
命名空间。
因此,为其定义路由的正确方法是为其指定完整的命名空间。参见示例:
<?php
Route::get('/signup', [
'uses' => '\App\Modules\Customers\Http\Controllers\CustomersController@signup',
'as' => 'customer.signup'
]);
另一种(更好的)方法是为应用程序的每个“模块”定义一个专用的RouteServiceProvider
。检查app/Providers/RouteServiceProvider.php
文件下的默认提供商,了解其工作原理。