RdlP
RdlP

Reputation: 1396

Controller doesn't work in route.php in Laravel

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)
    {
        //
    }
}

Upvotes: 1

Views: 1763

Answers (2)

Skysplit
Skysplit

Reputation: 1943

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;

Upvotes: 0

Alexey Mezenin
Alexey Mezenin

Reputation: 163978

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

Upvotes: 2

Related Questions