Reputation: 4539
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 :
Thanks ahead !!
Upvotes: 0
Views: 1099
Reputation: 5395
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.
Upvotes: 7