baris61's avatar

baris61 liked a comment+100 XP

3w ago

It would be nice to show how exactly to scaffold the VueJS application as I'm not very familiar with Vue.

baris61's avatar

baris61 liked a comment+100 XP

5mos ago

Great question! Structuring your Blade resources for clarity and scalability is important, especially when you have distinct public and admin sections. Here’s an approach that follows Laravel conventions and is maintainable as your app grows.

1. Directory Structure

Consider the following structure inside resources/views:

2. Layouts

  • Keep layouts together in resources/views/layouts/ for easy access:
    • public.blade.php for the public-facing site
    • admin.blade.php for the dashboard/admin area
    • auth.blade.php for authentication pages if needed

3. Components & Partials

  • Reusable UI elements (navbar, footer, etc.):
    • If you’ll reuse it across the site or in different layouts (navbar, footer, alerts, etc.), use Blade components.
    • Place them in resources/views/components/ or, for nested structure, consider sub-folders like components/public/navbar.blade.php.

Example of a Blade component:

{{-- resources/views/components/navbar.blade.php --}}
<nav>
    <!-- Navbar HTML -->
</nav>

Usage:

<x-navbar />
  • For less-reusable, very layout-specific includes (like an admin sidebar), you can still use Blade @include partials in a folder like partials/ (or stick with components for consistency).

Example:

{{-- resources/views/partials/admin/sidebar.blade.php --}}
<aside>
    <!-- Sidebar menu -->
</aside>

Usage:

@include('partials.admin.sidebar')

4. Views

  • Separate by context for public and admin:
    • All public views in views/public/
    • All admin views in views/admin/
    • Group related pages by feature (ex: news/, vacancies/)
    • This avoids naming confusion and keeps related files together.

5. Example Usage in Views

Example (admin news listing):

{{-- resources/views/admin/news/index.blade.php --}}
@extends('layouts.admin')

@section('content')
    <h1>Admin: News</h1>
    <x-admin.news-table :news="$news" />
@endsection

6. Why This Works

  • Maintainability: Shared code is DRY via layouts/components.
  • Clarity: Easy to tell what’s public vs admin.
  • Scalability: Add new sections/providers with clear boundaries.
  • Leverages Laravel Blade features: Components handle complex UI; layouts manage basic structure.

In summary:
Organize by context (public/admin), keep layouts together, use Blade components for reusable parts, and group views by feature where possible. This is clean, conventional, and future-proof!

Let me know if you’d like to see a more in-depth example or have questions about Blade components!

baris61's avatar

baris61 started a new conversation+100 XP

5mos ago

I’m currently organizing the Blade files for my Laravel project, and I’d love to get some input on best practices regarding directory structure.

The application has two clear sections:

Public — accessible to all visitors (news, vacancies, contact pages, etc.)

Admin — private dashboard for managing content (CRUD for news, vacancies, etc.)

At the moment, I’m not sure what the most maintainable structure would be for directories like: layouts/

components/

views/ (public vs. admin separation)

For example:

Should I keep all layouts together in resources/views/layouts (like public.blade.php, admin.blade.php, and auth.blade.php)?

Should partials like the navbar and footer live in partials/ or become Blade components?

How do you usually organize views when you have both a public site and an admin dashboard?

I’m mainly looking for a clean and scalable structure that follows common Laravel conventions. Any best practice examples or folder layouts would be really appreciated.

Thanks in advance!