jc1992
jc1992

Reputation: 644

Difficulties in routes with translations in Laravel 5

Good afternoon !

I have problems with file routes , I am using this format to recieve the view

   Route::group(array('prefix' => Config::get('app.locale_prefix')), function()
    {

        Route::get(
            '/{contact}',
            function () {
                return View::make('main');
            }
        );
    });

but I prefer using the following instruction

Route::get('home', 'HomeController@index');

Could anyone help to me for substitute the first methodology for the second ?

Upvotes: 0

Views: 35

Answers (1)

Bogdan
Bogdan

Reputation: 44526

Just create a controller file in your app/Http/Controllers folder called HomeController.php. You can do that manually or by running the following command in your app directory:

php artisan make:controller HomeController --plain

In the newly generated controller you need to add the index method that returns your view like you did in your route closure:

namespace App\Http\Controllers;

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

class HomeController extends Controller
{
    public function index()
    {
        return View::make('main');
    }
}

And that's about all there is to it, you can now use the route definition Route::get('home', 'HomeController@index'); and it will run the code in your index action.

In the future it would really pay off to read the documentation first, because in most cases it offers all the information you need.

Upvotes: 1

Related Questions