# Views

Views are the Blade templates your controller returns. Each Krayin package owns its own view folder and registers a view namespace so callers can reference them with package::path.to.view.

For Blade-specific syntax, see the Laravel views (opens new window) and Blade docs (opens new window).

# ๐Ÿ“ Create the views folder

By convention each package's templates live under src/Resources/views/, with one folder per Blade group:

packages
โ””โ”€โ”€ Webkul
    โ””โ”€โ”€ Example
        โ””โ”€โ”€ src
            โ”œโ”€โ”€ ...
            โ””โ”€โ”€ Resources
                โ””โ”€โ”€ views
                    โ””โ”€โ”€ admin
                        โ”œโ”€โ”€ index.blade.php
                        โ”œโ”€โ”€ create.blade.php
                        โ””โ”€โ”€ edit.blade.php

# Standard Blade files

Krayin uses a consistent naming convention for CRUD pages:

File Used for Controller action
index.blade.php List view (with DataGrid) index()
create.blade.php Create form create()
edit.blade.php Edit form edit()
show.blade.php Detail view (optional) show()

# ๐Ÿงฑ Write a basic template

Wrap your content in the shared admin layout component so it picks up the sidebar, header, and theming for free:

<x-admin::layouts>
    <x-slot:title>
        @lang('example::app.examples.index.title')
    </x-slot>

    <div class="flex justify-between items-center max-sm:flex-wrap gap-4">
        <p class="text-xl font-bold dark:text-white">
            @lang('example::app.examples.index.title')
        </p>
    </div>

    {{-- Page content goes here --}}
</x-admin::layouts>

Common pieces โ€” <x-admin::layouts>, breadcrumbs, datagrid, buttons โ€” are documented in the Blade Components guide.

# โš™๏ธ Register the views with the service provider

The view namespace is what lets you write view('example::admin.index'). Register it in boot():

<?php

namespace Webkul\Example\Providers;

use Illuminate\Support\ServiceProvider;

class ExampleServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        $this->loadViewsFrom(__DIR__ . '/../Resources/views', 'example');
    }
}

loadViewsFrom() takes the absolute path to the views folder and a short namespace ('example'). After this, anywhere in the app can render your templates with the example:: prefix.

# ๐Ÿ”Œ Render a view from a controller

The view() helper takes the namespaced view name and an optional data array:

public function index()
{
    $examples = $this->exampleRepository->with('children')->all();

    return view('example::admin.index', compact('examples'));
}

The variables passed in via compact() (or as a plain array) become available inside the Blade template as $examples, etc.

# ๐Ÿงช Verify

Visit the route from your browser:

http://your-krayin.local/admin/examples

You should see the rendered template. If you get a View [example::admin.index] not found. error, check:

  1. The view file actually exists at the path Laravel is looking at.
  2. loadViewsFrom() is in the service provider's boot() method, not register().
  3. Run php artisan view:clear to drop any cached compiled views.

# ๐Ÿ“ Next steps

  • Layouts โ€” the shared <x-admin::layouts> wrapper used above.
  • Blade Components โ€” full list of reusable admin UI primitives (breadcrumbs, datagrid, modals, etc.).
  • Localization โ€” replace hard-coded strings with @lang('example::app.โ€ฆ') keys.