R
R
Rishat Sultanov2017-03-20 17:25:00
Laravel
Rishat Sultanov, 2017-03-20 17:25:00

How to solve the problem of passing data from controller to view?

Good evening gentlemen.
I can't figure out the logic behind the output.
In general, the picture is as follows:
There are several views
In one main view (index.blade.php) another view (my_menu.blade) is called.
In which the problem begins to be observed
I have localization and when I go to the page rishat.kg/ru/page-eng/change everything works fine.
But as soon as I want to make a transition to this page with a menu that is implemented in my_menu.blade, the problem with localization begins. Since just a link selected from the database is transmitted and the localization does not want to stick because there is no route : of the form: = {{ route('rusNewsShow',['slug'=>$item->slug]) }}"
I just can't figure out how to push this route without breaking {{ $item_c->url }} in which the link is fetched from the database - which is indicated in the admin panel.
Sources:
https://gist.github.com/Rishats/e69828fe248dd162c9...
Video (I described the problem as best I could :( )
https://www.youtube.com/watch?v=LKW67RQII4w&featur...
PS I feel what I call things not in their proper names.I would be glad if you correct it :)
UPD
my_menu.blade.php

@foreach($items as $item)
            <li>
                <a href="{{ $item->url }}">{{ $item->title }}</a>
                @if($item->children)
                    <ul class="submenu">
                    @foreach($item->children as $item_c)
                        <li><a href="{{ $item_c->url }}">{{ $item_c->title }}</a></li>
                    @endforeach
                    </ul>
                @endif
            </li>
            @endforeach]

How to pass a route to this loop?
{{ route('rusPageShow',['slug'=>$item->slug]) }}
Instead of variables
{{ $item->url }}
{{ $item_c->url }}
Visibility problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mokhirjon Naimov, 2017-03-20
@rishatss

My version:

// Routes
Route::group(['prefix' => LaravelLocalization::setLocale()], function() {
    Route::get('/', '[email protected]');
    Route::get('news/{id}', '[email protected]')->name('show.news');
    Route::get('page/{slug}', '[email protected]')->name('show.page');
});

// Views
<a href="{{ app()->getLocale() . $item->url }}">{{ $item->title }}</a>

PS Your version is somehow not logical;)
$table_name = 'pages_' . config('app.locale');
$pages = \DB::table($table_name)->get();

Well, in general, you have a bad localization structure. You need to rethink and restructure the localization or use a ready-made CMS for multilingual content. And then you get bad customization ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question