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.
- Host: GitHub
- URL: https://github.com/eramitgupta/laravel-setup-layout
- Owner: eramitgupta
- License: other
- Created: 2024-03-02T05:49:02.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-04T17:08:49.000Z (about 1 year ago)
- Last Synced: 2024-11-16T05:24:26.679Z (about 1 year ago)
- Topics: laravel, laravellayouts, layoutmanagement, php-library, phpframework, webdevelopment
- Language: PHP
- Homepage:
- Size: 46.9 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Advanced Layout Setup for Laravel Applications ๐ฅ

[](https://github.com/eramitgupta/laravel-setup-layout/blob/main/LICENSE)
[](https://packagist.org/packages/erag/laravel-setup-layout)
[](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/)