1

I was working on a project that works fine and I now I have restored a backup of the project, the project and the backup is identical, I also change the backup name to the original name and now the controllers inside route.php doesn't work.

For do the backup and restore it I did

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

In my routes.php I have:

<?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', 'UserController@getLogin');

When I enter in /password in a web browser its work fine. The output is:

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

But when I enter in /login I get

GET http://project/public/index.php/login [HTTP/1.0 500 Internal Server Error 247ms]

in my UserController I have:

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

In fact, the laravel.log doesn't log anything. it seem that this function doesn't execute.

Why controller doesn't work?

My version of laravel is:

Laravel Framework version 5.2.30

Thanks

Edit: UserController.php code

<?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)
    {
        //
    }
}
4
  • can you paste the content of the UserController ? Commented Aug 26, 2016 at 11:49
  • It would be nice if you post UserController source code, just as @osleonard said. Commented Aug 26, 2016 at 12:03
  • I have updated the post with the source code. Thanks Commented Aug 26, 2016 at 12:09
  • @RdlP Use Hash in use statement. you are using Hash::make('12345678') , but didn't declare it in Use statement. Commented Aug 26, 2016 at 14:02

2 Answers 2

2

You're using wrong address to access /login route, it should be:

 http://project/login

If it doesn't work, you also need to setup web server by setting document root to laravel_project/public directory.

Also:

  • check /storage/logs/laravel.log for errors
  • set correct permissions to a storage folder and all files and folders in it
  • clear app and route cache:

php artisan cache:clear

php artisan route:clear

Sign up to request clarification or add additional context in comments.

3 Comments

before restore backup I accesses the same way that I have posted. So this is not the problem. And as I said above, laravel.log doesn't log anything.
Still, this can easily be a problem. Also, set correct permissions on a storage directory and try to clear app & route cache.
Finally the problem was the permissions. I run the cp command as root so, with a simple chown -R www-data:www-data over the project the problem was fixed. Thanks
0

You're using Hash facade, though you did not declare it's use in use statements.

PHP tried to resolve class in your 'App\Http\Controllers` namespace, thus trying to find App\Http\Controllers\Hash class which does not exist.

Adding use Hash; in the file should fix your problem.

use Auth;

use Log;

use Hash;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.