2016-08-26 19 views
1

我正在開發一個工作正常的項目,現在我已經恢復了項目的備份,項目和備份完全相同,我還將備份名稱更改爲原來的名字,現在route.php中的控制器不起作用。控制器不能在Laravel的route.php中工作

對於做備份和恢復它,我做了

cp -r project/ project_backup 
rm -r project 
cp -r project_backup/ project 

在我的routes.php文件我有:

<?php 

/* 
|-------------------------------------------------------------------------- 
| Routes File 
|-------------------------------------------------------------------------- 
| 
| Here is where you will register all of the routes in an application. 
| It's a breeze. Simply tell Laravel the URIs it should respond to 
| and give it the controller to call when that URI is requested. 
| 
*/ 



/* 
|-------------------------------------------------------------------------- 
| Application Routes 
|-------------------------------------------------------------------------- 
| 
| This route group applies the "web" middleware group to every route 
| it contains. The "web" middleware group is defined in your HTTP 
| kernel and includes session state, CSRF protection, and more. 
| 
*/ 

Route::get("/password", function(){ 
     $password = Hash::make('12345678'); 
     echo $password; 
    }); 
Route::get('/login', '[email protected]'); 

當我在/密碼,在Web瀏覽器中輸入其做工精細。輸出是:

$2y$10$.grNtTpANndXN0V3/rn9buSO470jPEeVWVyc00rupU6iNt9G.DMZC 

但是,當我在/登錄進入我得到

GET http://project/public/index.php/login [HTTP/1.0 500內部服務器錯誤247ms]

在我UserController中我有:

public function getLogin(){ 
     Log::info("getLogin"); 
     $password = Hash::make('12345678'); 
     echo $password; 
    } 

實際上,laravel.log doesn不記錄任何東西。看起來這個功能沒有執行。

爲什麼控制器不起作用?

我laravel的版本是:

Laravel Framework版本5.2.30

感謝

編輯:UserController.php代碼

<?php 

namespace Ordered\Http\Controllers; 

use Ordered\User; 

use Illuminate\Http\Request; 

use Ordered\Http\Requests; 

use Auth; 

use Log; 

class UserController extends Controller 
{ 
    /** 
    * Display a listing of the resource. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function index() 
    { 
     // 
     $user = User::all(); 
     return response()->json(["error"=>false, "data"=>$user->load("bars")],200); 
    } 

    public function getLogin(){ 
     Log::info("getLogin"); 
     $password = Hash::make('12345678'); 
     echo $password; 
    } 

    public function postLogin(Request $request){ 
     $input = $request->all(); 
     Log::info($input["email"]); 
     Log::info($input["password"]); 
     if (Auth::attempt(['email' => $input["email"], 'password' => $input["password"]], true)) 
     { 
      Log::info("postInfo"); 
      return redirect()->intended('/tables'); 
     } 

    } 

    public function apiLogin(Request $request){ 
     $input = $request->all(); 
     if (Auth::attempt(['username' => $request->header("u"), 'password' => $request->header("p")])) 
     { 
      return response()->json(["error"=>false, "data"=>Auth::user()->load("bars")],200); 
     } 
     return response()->json(["error"=>true, "data"=>""],401); 
    } 

    /** 
    * Show the form for creating a new resource. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function create() 
    { 
     // 
    } 

    /** 
    * Store a newly created resource in storage. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @return \Illuminate\Http\Response 
    */ 
    public function store(Request $request) 
    { 
     // 
    } 

    /** 
    * Display the specified resource. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function show($id) 
    { 
     // 
    } 

    /** 
    * Show the form for editing the specified resource. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function edit($id) 
    { 
     // 
    } 

    /** 
    * Update the specified resource in storage. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function update(Request $request, $id) 
    { 
     // 
    } 

    /** 
    * Remove the specified resource from storage. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function destroy($id) 
    { 
     // 
    } 
} 
+0

您可以粘貼UserController的內容嗎? – osleonard

+0

就像@osleonard說的那樣,如果你發佈'UserController'源代碼就好了。 – Skysplit

+0

我已經更新了帖子的源代碼。謝謝 – RdlP

回答

2

您使用錯誤的地址訪問/login路由,應該是:

http://project/login 

如果它不工作,你還通過設置document root to laravel_project/public directory需要設置Web服務器。

另外:

  • 檢查/storage/logs/laravel.log錯誤
  • 設置正確的權限爲storage文件夾和所有文件和文件夾在它
  • 明確的應用和路由緩存:

php artisan cache:clear

php artisan route:clear

+0

我訪問的方式與我發佈的方式相同。所以這不是問題。正如我上面所說,laravel.log不記錄任何東西。 – RdlP

+0

不過,這很容易成爲一個問題。另外,在「storage」目錄中設置正確的權限並嘗試清除應用程序和路由緩存。 –

+1

最後問題是權限。我以root用戶身份運行cp命令,通過一個簡單的chown -R www-data:www-data來解決問題。謝謝 – RdlP

0

您正在使用Hash正面,雖然您沒有聲明它在use語句中使用。

PHP試圖解決你的'App \ Http \ Controllers'命名空間中的類,因此試圖找到App\Http\Controllers\Hash類不存在。

在文件中添加use Hash;應該解決您的問題。

use Auth; 

use Log; 

use Hash;