justijn's avatar

Best practice CMS

So i kinda have a big question:

1

I'm building a website with Backpack for Laravel. I plan on using the base of if for a couple of websites. And I came up with a few difficulties.

I want the user to have full control over the routes. This brings up my first question:

Every request goes through this route:

Route::get('{page}/{subs?}', ['uses' => 'PageController@index'])
        ->where(['page' => '^((?!admin).)*$', 'subs' => '.*']);

I created a Service Provider that does something like this in the boot method:

View::composer(
    'pages.news.index', 'App\Http\ViewComposers\NewsComposer'
);

and then the NewsComposer class gets the correct data for that specific view.

public function compose(View $view)
{
    $view->with('news', $this->news);
}

So if I create a page with news template, my pageController checks which template that page has, then shows the according view for that page and lastly my service provider + NewsComposer feeds my view with the correct data.

If i want the news detail i have to surf to /news/detail/{slug}. That way my pageController sees the 'detail' and instead of showing pages.news.index, i show pages.news.detail and another Composer class will give my view the correct data

Is this a good setup?

2

My cms is multilanguage. I chose to handle everything as multilingual.

I don't want my objects to be duplicated in the different languages. Backpack gives us a little bit of help with the laravel-translatable package from spatie.

So i moved all the backpack plugins out of the vendor folder so i can modify them. To handle my frontend i use laravel-localization to get my language in my url. This gives me 2 separate packages for my languages.

I just wanna know if this is the best setup I can have or if you guys have better experience with other solutions.

3

What if i want to have a contact form? I don't have something like this defined in my routes:

Route::post('/contact', 'ContactController@store');

Whats the best way to save my form?

I chose to do it with Vue and an api route.

My form is now a vue component. But my site is multilingual, so to get my labels inside the js file I created a route that returns all my labels and i've put it inside a global variable so i can do something like this: {{ trans('auth.email') }}

conclusion

I'm fairly new to Laravel and especially to Vue. I would like some tips, best practices, ... Am I building my site correctly? If i wanna scale my project will it become too messy?

Any input is welcome! :)

0 likes
0 replies

Please or to participate in this conversation.