0

Hello !

I'm a beginner with Laravel. I wanted to experiment a little, so I made a basic controller using make:controller and started playing in its index() function. I simply wrote this :

return "Hello - ".Request::ip()." - ".Input::get('id');

And get a 500 internal server error when calling to the relevant route

mysite.com/public/emails?id=1

It works if I take out Request::ip() though, showing Hello - 1 without any problem.

The route :

Route::get('emails', 'EmailsController@index');

The includes at the beginning of the controller :

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

use \Input;

I would like to know 2 things :

  • Why is that error popping ? I saw a lot of tutorials using this without any problem
  • How can I debug efficiently in that sort of case ? There is nothing in the log @storage/logs/ and the page displays nothing as well.

Thanks ahead !!

1
  • 1
    also remember to check apache logs Commented May 18, 2015 at 20:18

1 Answer 1

7

You have to pass an Request object in the index method like so:

public function index(Request $request)
{
    return $request->ip;
}

It's the way Laravel 5 changed. In Laravel 4 your code should work. They kind of separated it to make it more readable.

This is much cleaner and more OOP style. If you want to make your code more OO(Object Oriented) then use this.

And I think it's a good practice to use this, because most of the Laravel 5 developers are using this style.

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

3 Comments

Thanks, you were right ! Do you know about my second question how to debug that kind of stuff ?
do you enabled debugging mode in your .env file? If not, then set APP_DEBUG=false to APP_DEBUG=true. the .env file is located in your root directory of your Laravel app.
Thanks, it was on true though :)

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.