Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JJK's avatar
Level 1

Plenty of small questions, but I'd rather have them answered

Good afternoon, I've built a buckload of projects on top of Laravel and so far I've always been satisfied with them.

My issue is though, I have a few questions that are more a matter of convention and making your work easier rather than making the project work in general.

So here are my questions (I would be thankful if you entered letter of question you are replying to):

a) If my website is split into 4 pages: greeting (home), about, products, contact - considering 3 of these 4 pages don't actually have any model attached to them (they do not store or read data from database), SHOULD I create separate controllers (GreetingController, AboutController etc. or is it just fine if I have a PageController with not very "CRUDy" function names like "showHome, showAbout, showContact"

b) I've removed the default auth system (controllers, even language files) - will I still be able to use bladee's @auth with my own system if I implemented one?

c) All my projects were deployed straight to the hosting server, which means I could edit .env afterwards, but what if I post my project on github and people who have no experience with laravel use it - is there any console command I can tell them to run to generate .env file with their personal key and walk them through configuring the rest of env file?

I'm sorry if some of these questions sound jibberish, I'm kinda slow due to recent heatwaves in my country.

0 likes
3 replies
Cronix's avatar

a) If you want. Personally I'd use a single PageController as you are, until it got too big. They're just static pages with no create/update/destroy methods. Just read methods. You could also simplify it a bit more by having a single catch-all route using a wildcard, and the controller would just pass back the appropriate view. So you'd just need one method instead of a method for each "page". Just check if the view file exists and 404 if not.

c) include a .env.example file that has all of the settings (minus the actual values). That's what laravel does (and composer copies it to .env). If you check the repo, there isn't an actual .env file.

For A, something like this as your last route in web.php file (not tested)

Route::get('/{page}', 'PageController@show');
public function show($page) {
    if (View::exists('pages.' . $page)) {
        return view('pages.' . $page);
    }
    
    abort(404);
}

assuming you have

/resources/views/pages/home.blade.php
/resources/views/pages/about.blade.php

etc

Edit: There are also View routes, so you don't actually need a controller. I like the catch-all controller though, but depends on your needs and how many views you have.

Route::view('/welcome', 'welcome');
1 like
JJK's avatar
Level 1

@Cronix thanks for the reply, I was actually using the Route::view(url, view);, but I thought it's not conventionally good.

Please or to participate in this conversation.