Skip to content

Commit

Permalink
bootstrap support
Browse files Browse the repository at this point in the history
Signed-off-by: Ritesh Singh <[email protected]>
  • Loading branch information
riteshsingh1 committed May 6, 2021
1 parent 93b488a commit 6498c3a
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/Commands/Crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ protected function getStub()
{
$this->checkIfModelExists();

if(config('livecrud.template') == 'bootstrap')
{
if (file_exists(base_path() . '/stubs/bootstrap.crud.php.stub')){
return base_path() . '/stubs/bootstrap.view.php.stub';
}
return base_path().'/vendor/imritesh/livecrud/src/stubs/bootstrap.crud.php.stub';
}

if (file_exists(base_path() . '/stubs/crud.php.stub')){
return base_path() . '/stubs/crud.php.stub';
}
Expand Down
7 changes: 5 additions & 2 deletions src/Commands/LiveCrudView.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,12 @@ public function getInput($name): string
*/
protected function getStub()
{
if (config('livecrud.template') != 'tailwind')
if(config('livecrud.template') == 'bootstrap')
{
throw new \Exception(config('livecrud.template').' is not currently supported, only supported template is tailwind css');
if (file_exists(base_path() . '/stubs/bootstrap.view.php.stub')){
return base_path() . '/stubs/bootstrap.view.php.stub';
}
return base_path().'/vendor/imritesh/livecrud/src/stubs/bootstrap.view.php.stub';
}

if (file_exists(base_path() . '/stubs/view.php.stub')){
Expand Down
128 changes: 128 additions & 0 deletions src/stubs/bootstrap.crud.php.stud
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php

namespace {{ namespace }};

{{ useclasses }}

class {{ name }} extends Component
{
use WithPagination;

public $paginate = 10;

{{ properties }}

public $mode = 'create';

public $showForm = false;

public $primaryId = null;

public $search;

public $showConfirmDeletePopup = false;

{{ rules }}


public function updated($propertyName)
{
$this->validateOnly($propertyName);
}

public function updatingSearch()
{
$this->resetPage();
}

public function render()
{
{{ query }}
return view('livewire.{{ blade }}', [
'rows'=> $model
]);
}


public function create ()
{
$this->mode = 'create';
$this->showForm = true;
}


public function edit($primaryId)
{
$this->mode = 'update';
$this->primaryId = $primaryId;
$model = Model::find($primaryId);

{{ setedibleval }}


$this->showForm = true;
}

public function closeForm()
{
$this->showForm = false;
}

public function store()
{
$this->validate();

$model = new Model();

{{ codeTosave }}

$this->resetForm();
session()->flash('message', 'Record Saved Successfully');
$this->showForm = false;
}

public function resetForm()
{
{{ reset }}
}


public function update()
{
$this->validate();

$model = Model::find($this->primaryId);

{{ codeTosave }}

$this->resetForm();

session()->flash('message', 'Record Updated Successfully');
}

public function confirmDelete($primaryId)
{
$this->primaryId = $primaryId;
$this->showConfirmDeletePopup = true;
$this->emit('showConfirmDelete');
}

public function hideConfirmationModal()
{
$this->emit('hideConfirmDelete');
}

public function destroy()
{
Model::find($this->primaryId)->delete();
$this->showConfirmDeletePopup = false;
$this->emit('hideConfirmDelete');
session()->flash('message', 'Record Deleted Successfully');
}

public function clearFlash()
{
session()->forget('message');
}

}
135 changes: 135 additions & 0 deletions src/stubs/bootstrap.view.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<div>
@if (session()->has('message'))
<div class="flex mx-auto">
<div class="alert alert-success">
<span class="inline-block align-middle mr-8">
<b class="capitalize">Success!</b> {{ session('message') }}
</span>
<button wire:click="clearFlash()"
class="float-right btn-xs btn-success btn-outline">
<span>×</span>
</button>
</div>
</div>
@endif
<div>
<div class="row">
<div class="col-md-3">
<input wire:model="search"
class="form-control"
id="search" type="text" name="search" wire:model="search" required="required"
autofocus="autofocus"/>
</div>
<div class="col-md-9 float-right">
<button type="button"
class="btn btn-primary float-right"
data-toggle="modal" data-target="#exampleModal"
wire:click="create">
Add New User
</button>
</div>
</div>
</div>
<div class="flex row">
<div class="card-body">
<table width="100%" class="table table-bordered">
<thead>
<tr>

<th scope="col">
NAME
</th>

<th scope="col">
EMAIL
</th>

<th scope="col">
PASSWORD
</th>


<th scope="col">
<span class="float-right">Actions</span>
</th>
</tr>
</thead>
<tbody>
@foreach($rows as $row)
<tr>
<td>{{ $row->name}}</td>

<td>{{ $row->email}}</td>

<td>{{ $row->password}}</td>

<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<a href="void(0)" class="text-indigo-600 hover:text-indigo-900"
wire:click="edit({{ $row->id }})" data-toggle="modal" data-target="#exampleModal">Edit</a>
<a href="#" class="text-indigo-600 hover:text-indigo-900"
wire:click="confirmDelete({{ $row->id }})">Delete</a>
</td>
</tr>@endforeach

</tbody>
</table>
<div class="p-2">
{{ $rows->links() }}
</div>
</div>


</div>


{{-- create / edit form --}}
<div wire:ignore>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"> {{ $mode == 'create' ? 'Add New Record' : 'Update Record ' }}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
{{ form }}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" @if($mode == 'create') wire:click="store()" @else wire:click="update()" @endif class="btn btn-primary">
{{ $mode == 'create' ? 'Save Record' : 'Update Record' }}
</button>
</div>
</div>
</div>
</div>
</div>
{{-- /create /edit form--}}


{{-- delete popup--}}
<div wire:ignore>
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Are You Sure?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
This Action Can not be Undone.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" wire:click="destroy()" class="btn btn-danger">Delete</button>
</div>
</div>
</div>
</div>
</div>
{{-- /delete popup--}}
</div>

0 comments on commit 6498c3a

Please sign in to comment.