user3384514
user3384514

Reputation: 297

generate link to pages in laravel issue

I have a problem with link in laravel.

I have this route:

$lingua = Request::segment(1);

Route::group(array('prefix' => $lingua), function()
{

    Route::get('/', 'ItemController@menu');
    Route::get('/{idcampo}/{idcat}','ItemController@show');
});

The first is language and request the 1st segment, and use as prefix. in / THis is my ItemController Controller

public function menu()

    {$lingua = Request::segment(1);
        return View::make('index', ['categorie'=>DB::table('cat_nome')->join('lingua', 'cat_nome.id_lingua', '=', 'lingua.id') ->where('lingua.lingua','=',$lingua)->get(),
                                    'campi' => DB::table('campo_nome')->join('lingua', 'campo_nome.id_lingua', '=', 'lingua.id') ->where('lingua.lingua','=',$lingua)->get(),
                                    'lingua'=>$lingua,
                                    ]
            );
    }


    public function show($camps,$cats)
    {$lingua = Request::segment(1);

    return View::make('categorie', ['categorie'=>DB::table('cat_nome')->join('lingua', 'cat_nome.id_lingua', '=', 'lingua.id') ->where('lingua.lingua','=',$lingua)->get(),
                                    'campi' => DB::table('campo_nome')->join('lingua', 'campo_nome.id_lingua', '=', 'lingua.id') ->where('lingua.lingua','=',$lingua)->get(),
                                    'dd' => DB::table('description')->join('lingua', 'description.id_lingua', '=', 'lingua.id')->where('lingua.lingua','=',$lingua)->where ('description.id_cat','=',$cats)->where ('description.id_campo','=',$camps)->select('description.descrizione')->get(),
                                    'lingua' => $lingua,
                                    ]);
    }

In index i query a the entries of a menu.

@foreach ($campi as $campo)
{{$campo->nome}}
<ul class="list-unstyled">
@foreach($categorie as $categoria)
<li> <a href="{{$lingua}}/{{$campo->id_campo}}/{{$categoria->id_cat}}">{{$categoria->nome}}</a> </li>
@endforeach
</ul>
@endforeach

Now when i pass to the controller, i keep the menu visualized and i visualize the single entries of the database (the description).

My problem is that when i click the first time on the link, which appear to be: language/id1/id2 I go in the right page, visualize the description of the product BUT now the link on the side menu became:

language/id1/language/id1/id2

But it should always be language/id1/id2 even when i am in Itemcontroller@show

The second time the link are generated in the side menu, something is added on the link, and i can't quite understand why.

Upvotes: 1

Views: 152

Answers (1)

urbankid
urbankid

Reputation: 36

You might try to use URL::to like this:

<a href="{{ URL::to($lingua. '/'. $campo->id_campo. '/'. $categoria->id_cat) }}">

Upvotes: 2

Related Questions