Skip to content

Commit d2aca24

Browse files
committed
first commit
0 parents  commit d2aca24

17 files changed

+1658
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor
2+
composer.phar
3+
composer.lock
4+
.DS_Store

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Laravel 5.5.x Front-end Preset For Bootstrap 4
2+
3+
Preset for Bootstrap 4 scaffolding on new Laravel 5.5.x project.
4+
5+
*Current version*: **Bootstrap 4 beta**
6+
7+
## Usage
8+
1. Fresh install Laravel 5.5.x and `cd` to your app.
9+
2. Install this preset via `composer require laravel-frontend-presets/bootstrap-4`. Laravel 5.5.x will automatically discover this package. No need to register the service provider.
10+
3. Use `php artisan preset bootstrap4` for basic Bootstrap 4 preset. **OR** Use `php artisan preset bootstrap4-auth` for basic preset, Auth route entry and Bootstrap 4 Auth views in one go. (**NOTE**: If you run this command several times, be sure to clean up the duplicate Auth entries in `routes/web.php`)
11+
4. `npm install`
12+
5. `npm run dev`
13+
6. Configure your favorite database (mysql, sqlite etc.)
14+
7. `php artisan migrate` to create basic user tables.
15+
8. `php artisan serve` (or equivalent) to run server and test preset.

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "travoltron/bootstrap-4",
3+
"description": "Laravel 5.5.x Front-end preset for Bootstrap 4",
4+
"keywords": ["laravel", "preset", "bootstrap 4", "scaffolding"],
5+
"license": "MIT",
6+
"require": {
7+
"laravel/framework": "5.5.*"
8+
},
9+
"autoload": {
10+
"psr-4": {
11+
"Travoltron\\Bootstrap4Preset\\": "src/"
12+
}
13+
},
14+
"extra": {
15+
"laravel": {
16+
"providers": [
17+
"Travoltron\\Bootstrap4Preset\\Bootstrap4PresetServiceProvider"
18+
]
19+
}
20+
}
21+
22+
}

src/Bootstrap4Preset.php

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
namespace Travoltron\Bootstrap4Preset;
3+
4+
use Artisan;
5+
use Illuminate\Support\Arr;
6+
use Illuminate\Filesystem\Filesystem;
7+
use Illuminate\Foundation\Console\Presets\Preset;
8+
9+
class Bootstrap4Preset extends Preset
10+
{
11+
/**
12+
* Install the preset.
13+
*
14+
* @return void
15+
*/
16+
public static function install($withAuth = false)
17+
{
18+
static::updatePackages();
19+
static::updateSass();
20+
static::updateBootstrapping();
21+
static::updateMix();
22+
23+
if($withAuth)
24+
{
25+
static::addAuthTemplates();
26+
}
27+
else
28+
{
29+
static::updateWelcomePage();
30+
}
31+
32+
static::removeNodeModules();
33+
}
34+
35+
/**
36+
* Update the given package array.
37+
*
38+
* @param array $packages
39+
* @return array
40+
*/
41+
protected static function updatePackageArray(array $packages)
42+
{
43+
return [
44+
'bootstrap' => '^4.0.0-beta',
45+
'jquery' => '^3.2.1',
46+
'popper.js' => '^1.11.0',
47+
] + Arr::except($packages, ['foundation-sites', 'bootstrap-sass', 'bulma', 'uikit']);
48+
}
49+
50+
/**
51+
* Update the Sass files for the application.
52+
*
53+
* @return void
54+
*/
55+
protected static function updateSass()
56+
{
57+
// clean up orphan files
58+
$orphan_sass_files = glob(resource_path('/assets/sass/*.*'));
59+
60+
foreach($orphan_sass_files as $sass_file)
61+
{
62+
(new Filesystem)->delete($sass_file);
63+
}
64+
65+
copy(__DIR__.'/bootstrap4-stubs/_variables.scss', resource_path('assets/sass/_variables.scss'));
66+
copy(__DIR__.'/bootstrap4-stubs/app.scss', resource_path('assets/sass/app.scss'));
67+
}
68+
69+
/**
70+
* Update the bootstrapping files.
71+
*
72+
* @return void
73+
*/
74+
protected static function updateBootstrapping()
75+
{
76+
(new Filesystem)->delete(
77+
resource_path('assets/js/bootstrap.js')
78+
);
79+
80+
copy(__DIR__.'/bootstrap4-stubs/bootstrap.js', resource_path('assets/js/bootstrap.js'));
81+
}
82+
83+
/**
84+
* Update the mix file.
85+
*
86+
* @return void
87+
*/
88+
protected static function updateMix()
89+
{
90+
(new Filesystem)->delete(
91+
base_path('webpack.mix.js')
92+
);
93+
94+
copy(__DIR__.'/bootstrap4-stubs/webpack.mix.js', base_path('webpack.mix.js'));
95+
}
96+
97+
/**
98+
* Update the default welcome page file with Foundation buttons.
99+
*
100+
* @return void
101+
*/
102+
protected static function updateWelcomePage()
103+
{
104+
// remove default welcome page
105+
(new Filesystem)->delete(
106+
resource_path('views/welcome.blade.php')
107+
);
108+
109+
// copy new one with Bootstrap buttons
110+
copy(__DIR__.'/bootstrap4-stubs/views/welcome.blade.php', resource_path('views/welcome.blade.php'));
111+
}
112+
113+
/**
114+
* Copy Bootstrap Auth view templates.
115+
*
116+
* @return void
117+
*/
118+
protected static function addAuthTemplates()
119+
{
120+
// Add Home controller
121+
copy(__DIR__.'/bootstrap4-stubs/Controllers/HomeController.php', app_path('Http/Controllers/HomeController.php'));
122+
123+
// Add Auth route in 'routes/web.php'
124+
$auth_route_entry = "Auth::routes();\n\nRoute::get('/home', 'HomeController@index')->name('home');\n\n";
125+
file_put_contents('./routes/web.php', $auth_route_entry, FILE_APPEND);
126+
127+
// Copy Bootstrap4 Auth view templates
128+
(new Filesystem)->copyDirectory(__DIR__.'/bootstrap4-stubs/views', resource_path('views'));
129+
}
130+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
namespace Travoltron\Bootstrap4Preset;
3+
4+
use Illuminate\Support\ServiceProvider;
5+
use Illuminate\Foundation\Console\PresetCommand;
6+
7+
class Bootstrap4PresetServiceProvider extends ServiceProvider
8+
{
9+
/**
10+
* Bootstrap the application services.
11+
*
12+
* @return void
13+
*/
14+
public function boot()
15+
{
16+
PresetCommand::macro('bootstrap4', function ($command) {
17+
Bootstrap4Preset::install(false);
18+
$command->info('Bootstrap 4 scaffolding installed successfully.');
19+
$command->comment('Please run "npm install && npm run dev" to compile your fresh scaffolding.');
20+
});
21+
22+
PresetCommand::macro('bootstrap4-auth', function ($command) {
23+
Bootstrap4Preset::install(true);
24+
$command->info('Bootstrap 4 scaffolding with Auth views installed successfully.');
25+
$command->comment('Please run "npm install && npm run dev" to compile your fresh scaffolding.');
26+
});
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
7+
class HomeController extends Controller
8+
{
9+
/**
10+
* Create a new controller instance.
11+
*
12+
* @return void
13+
*/
14+
public function __construct()
15+
{
16+
$this->middleware('auth');
17+
}
18+
19+
/**
20+
* Show the application dashboard.
21+
*
22+
* @return \Illuminate\Http\Response
23+
*/
24+
public function index()
25+
{
26+
return view('home');
27+
}
28+
}

0 commit comments

Comments
 (0)