An open API service indexing awesome lists of open source software.

https://github.com/eramitgupta/laravel-setup-layout

A package for setting up layout in Laravel applications.
https://github.com/eramitgupta/laravel-setup-layout

laravel laravellayouts layoutmanagement php-library phpframework webdevelopment

Last synced: 4 months ago
JSON representation

A package for setting up layout in Laravel applications.

Awesome Lists containing this project

README

          

## Advanced Layout Setup for Laravel Applications ๐Ÿ”ฅ

Screenshot 2024-10-04 at 10 34 23โ€ฏPM

[![Packagist License](https://img.shields.io/badge/Licence-MIT-blue)](https://github.com/eramitgupta/laravel-setup-layout/blob/main/LICENSE)
[![Latest Stable Version](https://img.shields.io/packagist/v/erag/laravel-setup-layout?label=Stable)](https://packagist.org/packages/erag/laravel-setup-layout)
[![Total Downloads](https://img.shields.io/packagist/dt/erag/laravel-setup-layout.svg?label=Downloads)](https://packagist.org/packages/erag/laravel-setup-layout)


A versatile, easy-to-use package to streamline layout creation in Laravel.

## Features
- Simplifies layout management.
- Customizable configurations to fit your app's needs.
- Improves structure and organization in Laravel projects.

## Installation

Install the package via Composer:
```bash
composer require erag/laravel-setup-layout
```

### Step 1: Register Service Provider

#### Laravel 11.x
Ensure the service provider is registered in `/bootstrap/providers.php`:
```php
return [
// ...
LaravelSetupLayoutServiceProvider::class
];
```

#### Laravel 10.x
Add the service provider in `config/app.php`:
```php
'providers' => [
// ...
LaravelSetupLayout\LaravelSetupLayoutServiceProvider::class,
];
```

### Step 2: Publish Configuration

Run this command to publish the configuration file:
```bash
php artisan vendor:publish --tag=LaravelSetupLayout --force
```

### Step 4: assets `config/layout-assets.php`

```bash

Define web assets for different pages
'THEME_WEB_ASSETS' => [
'home' => [
// CSS files for the home page
'css' => [
'assets/css/demo.css',
],
// JavaScript files for the home page
'js' => [
'assets/js/demo.js',
],
],
// You can add more as per your requirement
],

#THEME_ASSETS Define global assets used across all pages
'THEME_ASSETS' => [
'global' => [
// Global CSS files, such as Bootstrap
'css' => [
'https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css',
// You can add more global CSS files here
],
// Global JavaScript files, such as Bootstrap JS
'js' => [
'https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js',
// You can add more global JavaScript files here
],
],
],

#THEME_VENDORS Define vendor assets specific to certain pages or components
'THEME_VENDORS' => [
'demo' => [
// CSS files for the login page or component
'css' => [
'assets/css/demo.css',
],
// JavaScript files for the login page or component
'js' => [
'assets/js/demo.js',
],
],
// You can add more as per your requirement
],
];
```

### Step 4: Usage ๐Ÿค”

#### Create a Controller
Generate a basic controller:
```bash
php artisan make:controller HomeController
```

#### Create a View
Create a view for your application:
```bash
php artisan make:view home
```
This will create `home.blade.php` in `resources/views`.

#### Subdirectory Controller
To create a controller in a subfolder, use:
```bash
php artisan make:controller Dashboard/HomeController
```
This creates `HomeController` under `app/Http/Controllers/Dashboard`.

#### Subdirectory View
For views in subdirectories:
```bash
php artisan make:view dashboard.home
```
Creates `home.blade.php` in `resources/views/dashboard`.

### Step 4: Define Routes

#### Home Route:
```php
Route::get('/', [App\Http\Controllers\HomeController::class, 'index']);
```

#### Dashboard Route:
```php
Route::get('/dashboard', [App\Http\Controllers\Dashboard\HomeController::class, 'dashboard']);
```

Ensure you have matching controller methods, like so:

```php
// HomeController.php
namespace App\Http\Controllers;

class HomeController extends Controller
{
public function index()
{
addWebAsset(['home']);
return view('home');
}
}

// Dashboard/HomeController.php
namespace App\Http\Controllers\Dashboard;

class HomeController extends Controller
{
public function dashboard()
{
addVendors(['demo']);
return view('dashboard.home');
}
}
```

### Step 5: Use Layout Components

Add the layout components in your Blade files:

#### Home Layout (Front-End)
```html

Welcome to the Front-End ๐Ÿ‘‹

```

#### Dashboard Layout
```html

Welcome to the Dashboard ๐Ÿ‘‹

```

### Blade Directives for Scripts and Styles

To include page-specific styles and scripts:
```html

@push('page_styles')

@endpush

@push('page_scripts')

@endpush
```

### Page Title Setup

To set the page title dynamically:
```php
// HomeController.php
public function index()
{
addWebAsset(['home', 'jq']);
$data['title'] = 'Home Page';
return view('home', $data);
}
```

And in your view:
```html

@section('title', $title)

Welcome to the Home Page ๐Ÿ‘‹

```

---

### License
The MIT License (MIT). See the License file for details.

> GitHub [@eramitgupta](https://github.com/eramitgupta) ย ยทย 
> LinkedIn [@eramitgupta](https://www.linkedin.com/in/eramitgupta/) ย ยทย 
> Support [Donate](https://paypal.me/teamdevgeek/)