Skip to content

Commit

Permalink
Update to Livewire 3
Browse files Browse the repository at this point in the history
  • Loading branch information
georgechitechi committed Jan 23, 2025
1 parent 3a4e0f6 commit 01f8bd1
Show file tree
Hide file tree
Showing 19 changed files with 244 additions and 248 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ php artisan crud:install
```
**This command will perfom below actions:

* Compile css/js based on `bootstrap and fontawesome/free`.
* Run `npm install && run dev`
* Flush *node_modules* files from you folder.
* Compile css/js based on `bootstrap and bootstrap-icons`.
* Run `npm install && run build`
* Flush *node_modules* files from your folder.

If you choose to scaffold authentication this command will run `php artisan ui:auth`
to generate Auth scaffolds using `laravel/ui` package. You can skip this step if your app has authentication already.
Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
],
"require": {
"php": "^7|^8",
"laravel/framework": "^6|^7|^8|<9.19",
"laravel/ui": "^2|^3|^4",
"livewire/livewire": "^2"
"laravel/framework": ">=9.19",
"laravel/ui": "^4",
"livewire/livewire": "^3"
},
"require-dev": {},
"autoload": {
Expand All @@ -35,7 +35,6 @@
"scripts": {
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"

},
"config": {
"sort-packages": true
Expand All @@ -50,4 +49,4 @@
}
}
}
}
}
4 changes: 4 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@
'namespace' => 'App\Http\Controllers',
],

'livewire' => [
'namespace' => 'App\Livewire',
],

];
26 changes: 10 additions & 16 deletions resources/install/package.json.stub
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
{
"private": true,
"type": "module",
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"@popperjs/core": "^2.11",
"axios": "^1.7",
"bootstrap": "^4.6",
"bootstrap": "^5.3",
"bootstrap-icons": "^1.11",
"cross-env": "^7.0",
"jquery": "^3.7.1",
"laravel-mix": "^6.0",
"lodash": "^4.17.21",
"popper.js": "^1.16.1",
"resolve-url-loader": "^5.0.0",
"sass": "^1.77.8",
"sass-loader": "^14.2.1"
"laravel-vite-plugin": "^1.0",
"lodash": "^4.17",
"postcss": "^8.4",
"sass": "1.76.0",
"vite": "^6.0"
}
}
6 changes: 5 additions & 1 deletion resources/install/resources/js/app.js.stub
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
require('./bootstrap');
//Import Bootstrap File
import './bootstrap';

// Import our custom CSS
import '../sass/app.scss'
15 changes: 8 additions & 7 deletions resources/install/resources/js/bootstrap.js.stub
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
window._ = require('lodash');
import _ from 'lodash';
window._ = _;

try {
window.Popper = require('popper.js').default;
window.$ = window.jQuery = require('jquery');
require('bootstrap');
} catch (e) {}
// Import all of Bootstrap's JS
import * as bootstrap from 'bootstrap'
window.bootstrap = bootstrap;

window.axios = require('axios');
// Import Axios
import axios from 'axios';
window.axios = axios;

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
9 changes: 5 additions & 4 deletions resources/install/resources/sass/app.scss.stub
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Fonts
@import url('https://fonts.bunny.net/css?family=Nunito');

// Variables
@import 'variables';

@import '~bootstrap/scss/bootstrap';
// Bootstrap
@import 'bootstrap/scss/bootstrap';

// Bootstrap Icons
@import '~bootstrap-icons/font/bootstrap-icons.css';

@import '../css/app.css';
@import 'bootstrap-icons/font/bootstrap-icons.css';
2 changes: 1 addition & 1 deletion resources/install/resources/views/home.blade.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="row justify-content-center">
<div class="col-md-12">
<div class="card">
<div class="card-header"><h5><span class="text-center bi-house-fill"></span> @yield('title')</h5></div>
<div class="card-header"><h5><span class="text-center bi-house"></span> @yield('title')</h5></div>
<div class="card-body">
<h5>Hi <strong>{{ Auth::user()->name }},</strong> {{ __('You are logged in to ') }}{{ config('app.name', 'Laravel') }}</h5>
</br>
Expand Down
39 changes: 17 additions & 22 deletions resources/install/resources/views/layouts/app.blade.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">

<title>@hasSection('title') @yield('title') | @endif {{ config('app.name', 'Laravel') }}</title>

<!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script>
<title>@hasSection('title') @yield('title') | @endif {{ config('app.name', 'Laravel') }}</title>

<!-- Fonts -->
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
<link href="https://fonts.bunny.net/css?family=Nunito" rel="stylesheet">

<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
@livewireStyles
<!-- Scripts -->
@vite(['resources/js/app.js'])
</head>
<body>
<div id="app">
Expand All @@ -27,7 +23,7 @@
<a class="navbar-brand" href="{{ url('/') }}">
{{ config('app.name', 'Laravel') }}
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
<span class="navbar-toggler-icon"></span>
</button>

Expand All @@ -38,29 +34,29 @@
<!--Nav Bar Hooks - Do not delete!!-->
</ul>
@endauth()

<!-- Right Side Of Navbar -->
<ul class="navbar-nav ml-auto">
<ul class="navbar-nav ms-auto">
<!-- Authentication Links -->
@guest
@if (Route::has('login'))
<li class="nav-item">
<a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
</li>
@endif

@if (Route::has('register'))
<li class="nav-item">
<a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
</li>
@endif
@else
<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
{{ Auth::user()->name }}
</a>

<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<div class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
Expand All @@ -78,15 +74,14 @@
</div>
</nav>

<main class="py-2">
<main class="py-4">
@yield('content')
</main>
</div>
@livewireScripts
<script type="text/javascript">
window.livewire.on('closeModal', () => {
$('#createDataModal').modal('hide');
});
</script>
<script type="module">
window.addEventListener('closeModal', () => {
bootstrap.Modal.getInstance(document.getElementById('DataModal')).hide();
})
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion resources/install/resources/views/welcome.blade.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="row justify-content-center">
<div class="col-md-12">
<div class="card">
<div class="card-header"><h5><span class="text-center bi-house-fill"></span> @yield('title')</h5></div>
<div class="card-header"><h5><span class="text-center bi-house"></span> @yield('title')</h5></div>
<div class="card-body">
<h5>
@guest
Expand Down
17 changes: 17 additions & 0 deletions resources/install/vite.config.js.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import path from 'path'

export default defineConfig({
plugins: [
laravel({
input: ['resources/js/app.js'],
refresh: true,
}),
],
resolve: {
alias: {
'~bootstrap': path.resolve(__dirname, 'node_modules/bootstrap'),
}
},
});
39 changes: 3 additions & 36 deletions src/Commands/LivewireCrudGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

namespace Flightsadmin\LivewireCrud\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Illuminate\Filesystem\Filesystem;
use File;

class LivewireCrudGenerator extends LivewireGeneratorCommand
{
Expand All @@ -19,11 +17,6 @@ class LivewireCrudGenerator extends LivewireGeneratorCommand

protected $description = 'Generate Livewire Component and CRUD operations';

/**
* Execute the console command.
* @return bool|null
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function handle()
{
$this->table = $this->getNameInput();
Expand Down Expand Up @@ -60,7 +53,7 @@ public function handle()
$layoutFile = 'resources/views/layouts/app.blade.php';
$layoutContents = $this->filesystem->get($layoutFile);
$navItemStub = "\t\t\t\t\t\t<li class=\"nav-item\">
<a href=\"{{ url('/".$this->getNameInput()."') }}\" class=\"nav-link\"><i class=\"bi-house-fill text-info\"></i> ". ucfirst($this->getNameInput()) ."</a>
<a href=\"{{ url('/".$this->getNameInput()."') }}\" class=\"nav-link\"><i class=\"bi-house text-info\"></i> ". ucfirst($this->getNameInput()) ."</a>
</li>";
$navItemHook = '<!--Nav Bar Hooks - Do not delete!!-->';

Expand All @@ -76,10 +69,6 @@ public function handle()
return true;
}

/**
* @return $this
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
protected function buildModel()
{
$modelPath = $this->_getModelPath($this->name);
Expand Down Expand Up @@ -112,11 +101,6 @@ protected function buildModel()
return $this;
}

/**
* @return $this
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
* @throws \Exception
*/
protected function buildViews()
{
$this->warn('Creating:<info> Views ...</info>');
Expand All @@ -138,21 +122,6 @@ protected function buildViews()

foreach ($this->getColumns() as $values) {
$type = "text";
// if (Str::endsWith(($values->Type), ['timestamp', 'date', 'datetime'])) {
// $type = "date";
// }
// elseif (Str::endsWith(($values->Type), 'int')) {
// $type = "number";
// }
// elseif (Str::startsWith(($values->Type), 'time')) {
// $type = "time";
// }
// elseif (Str::contains(($values->Type), 'text')) {
// $type = "textarea";
// }
// else{
// $type = "text";
// }
}

$replace = array_merge($this->buildReplacements(), [
Expand All @@ -165,7 +134,7 @@ protected function buildViews()

$this->buildLayout();

foreach (['view', 'index', 'create', 'update'] as $view) {
foreach (['view', 'index', 'modals'] as $view) {
$viewTemplate = str_replace(
array_keys($replace), array_values($replace), $this->getStub("views/{$view}")
);
Expand All @@ -178,8 +147,6 @@ protected function buildViews()

/**
* Make the class name from table name.
*
* @return string
*/
private function _buildClassName()
{
Expand All @@ -194,4 +161,4 @@ private function replace($content)

return $content;
}
}
}
Loading

0 comments on commit 01f8bd1

Please sign in to comment.