0
votes

I'm starting in on a Laravel project, and having come from past projects using BEM style folder layout (sort by block, not by type), I'd like to do the same within the views folder provided by Laravel. The benefits of having keeping these files together seem obvious, versus mirroring the folder structure in the js/sass folders, but there's some skepticism, prompting the question.

As an example, if I have a modal component, it would exist in:

views/components/modal

and it would consist of:

modal.blade.php
modal.scss
modal.js

So I'm wondering if there are any Laravel specific reasons why I wouldn't want to have a css & js file alongside an @component blade template.

1
I strongly believe you can use BEM structure for Laravel projects as well.tadatuta

1 Answers

0
votes

Many people in the Laravel community are using a CRUD/MVC like structure.

Example for views.

views/users/index.blade.php
views/users/show.blade.php
views/users/create.blade.php

views/posts/index.blade.php
views/posts/show.blade.php
views/posts/create.blade.php

Routes (with corresponding methods)

Route::get('/users', 'UserController@index);
Route::get('/users', 'UserController@show);
Route::get('/users', 'UserController@create);

Route::get('/posts', 'PostController@index);
Route::get('/posts', 'PostController@show);
Route::get('/posts', 'PostController@create);

Method example

public function show(User $user)
{
    return view('users.show', ['user' => $user]);
}

Blade example

<head>
    <!-- Styles -->
    <link href="{{ asset(css/posts.css) }}" rel="stylesheet">

</head>
<body>
    <div id="app">
        @yield('content')
    </div>

    <!-- Scripts -->
    <script src="{{ asset('js/posts.js) }}"></script>

</body>