Skip to content

Migrating to spatie/laravel-html from laravelcollective/html #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor/
/.idea/
composer.lock
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ If you find this project useful, please consider giving it a star⭐. It helps m

``` composer require mrdebug/crudgen --dev ```

2\. If you don't use Laravel Collective Form package in your project, install it:
2\. If you don't use Spatie's HTML package in your project, install it:

``` composer require laravelcollective/html ```
``` composer require spatie/laravel-html ```

<sub>(Note: This step is not required if you don't need views.)</sub>

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
],
"require":
{
"php": ">=8.0.0"
"php": ">=8.0.0",
"spatie/laravel-html": "^3.4"
},
"autoload":
{
Expand Down
21 changes: 15 additions & 6 deletions src/Services/MakeViewsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function findAndReplaceIndexViewPlaceholderColumns($columns, $templateVie
$column = $type[0];

// our placeholders
$thIndex .=str_repeat("\t", 4)."<th>".trim($column)."</th>\n";
$thIndex .=str_repeat("\t", 4)."<th scope='col'>".trim($column)."</th>\n";

if($column == $columnInSearch)
$indexView .=str_repeat("\t", 5).'<td>{!! $this->search ? $this->highlightTitle(DummyCreateVariableSing$->'.$columnInSearch.') : DummyCreateVariableSing$->'.$columnInSearch.' !!}</td>'."\n";
Expand Down Expand Up @@ -123,11 +123,16 @@ public function findAndReplaceCreateViewPlaceholderColumns($columns, $templateVi
$sql_type = (count($type)==2) ? $type[1] : 'string';
$column = $type[0];
$typeHtml = $this->getHtmlType($sql_type);
$number_types = ['decimal', 'float', 'double'];

// our placeholders
$formCreate .=str_repeat("\t", 2).'<div class="mb-3">'."\n";
$formCreate .=str_repeat("\t", 3).'{{ Form::label(\''.trim($column).'\', \''.ucfirst(trim($column)).'\', [\'class\'=>\'form-label\']) }}'."\n";
$formCreate .=str_repeat("\t", 3).'{{ Form::'.$typeHtml.'(\''.trim($column).'\', null, array(\'class\' => \'form-control\')) }}'."\n";
$formCreate .=str_repeat("\t", 3).'{{ html()->label(\''.ucfirst(trim($column)).'\', \''.trim($column).'\')->class(\'form-label\') }}'."\n";

$formCreate .=str_repeat("\t", 3).'{{ html()->'.$typeHtml.'(name: \''.trim($column).'\'';
if(in_array($sql_type, $number_types))
$formCreate .=", step: .000001";
$formCreate .=")->class('form-control') }}\n";
$formCreate .=str_repeat("\t", 2).'</div>'."\n";
}

Expand Down Expand Up @@ -160,8 +165,8 @@ public function findAndReplaceEditViewPlaceholderColumns($columns, $templateView

// our placeholders
$formEdit .=str_repeat("\t", 2).'<div class="mb-3">'."\n";
$formEdit .=str_repeat("\t", 3).'{{ Form::label(\''.trim($column).'\', \''.ucfirst(trim($column)).'\', [\'class\'=>\'form-label\']) }}'."\n";
$formEdit .=str_repeat("\t", 3).'{{ Form::'.$typeHtml.'(\''.trim($column).'\', null, array(\'class\' => \'form-control\')) }}'."\n";
$formEdit .=str_repeat("\t", 3).'{{ html()->label(\''.ucfirst(trim($column)).'\', \''.trim($column).'\') }}'."\n";
$formEdit .=str_repeat("\t", 3).'{{ html()->'.$typeHtml.'(\''.trim($column).'\', null }}'."\n";
$formEdit .=str_repeat("\t", 2).'</div>'."\n";
}

Expand Down Expand Up @@ -195,7 +200,11 @@ private function getHtmlType($sql_type)
[
'string' => 'text',
'text' => 'textarea',
'integer' => 'text'
'integer' => 'number',
'float' => 'number',
'double' => 'number',
'decimal' => 'number',
'bool' => 'checkbox'
];
return (isset($conversion[$sql_type]) ? $conversion[$sql_type] : 'string');
}
Expand Down
16 changes: 8 additions & 8 deletions src/stubs/commentable/views/comment-block.stub
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{!! Form::open(['route' => ['{{route_comment}}.store', {{parent_variable}}->id]]) !!}
{!! html()->form(route('{{route_comment}}.store', {parent_variable}}->id))->open() !!}
<div class="mb-3">
{{ Form::label('comment', 'Comment', ['class'=>'form-label']) }}
{{ Form::textarea('comment', null, array('class' => 'form-control')) }}
{{ html()->label('Comment', 'comment')->class('form-label)' }}
{{ html()->textarea()('comment')->class('form-control) }}
</div>
{{ Form::submit('Create', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
{{ html()->submit('Create')->class('btn btn-primary') }}
{{ html()->form()->close() }}

<div class="mt-3">
@foreach({{parent_variable}}->{{name_relationship}} as $comment)
<div class="card mb-3">
<div class="position-absolute" style="right: 0">
{!! Form::open(['method' => 'DELETE','route' => ['{{route_comment}}.destroy', {{comment_variable}}->id]]) !!}
{!! Form::submit('❌', ['class' => 'btn btn-sm']) !!}
{!! Form::close() !!}
{!! html()->form('DELETE', route('{{route_comment}}.destroy', {{comment_variable}}->id))->open() !!}
{!! html()->submit('❌')->class('btn btn-sm') !!}
{!! html()->form()->close() !!}
</div>
<div class="card-body">
<div class="d-flex flex-start">
Expand Down
13 changes: 5 additions & 8 deletions src/stubs/default-theme/create.stub
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
</div>
@endif

{!! Form::open(['route' => 'DummyVariable.store']) !!}
{{ html()->form('POST', route('DummyVariable.store') )->open() }}
DummyFormCreate
{{ html()->submit('Create')->class('btn btn-primary') }}
{{ html()->form()->close() }}

DummyFormCreate

{{ Form::submit('Create', array('class' => 'btn btn-primary')) }}

{{ Form::close() }}


@stop
@stop
10 changes: 4 additions & 6 deletions src/stubs/default-theme/edit.stub
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
</div>
@endif

{{ Form::model(DummyCreateVariableSing$, array('route' => array('DummyVariable.update', DummyCreateVariableSing$->id), 'method' => 'PUT')) }}

DummyFormCreate
{{ Form::submit('Edit', array('class' => 'btn btn-primary')) }}

{{ Form::close() }}
{{ html()->form('PUT', route(['DummyVariable.update', DummyCreateVariableSing$->id]) )->open() }}
DummyFormCreate
{{ html()->submit('Edit')->class('btn btn-primary') }}
{{ html()->form()->close() }}
@stop
19 changes: 7 additions & 12 deletions src/stubs/default-theme/index.stub
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
@extends('DummyExtends')

@section('DummySection')

<div class="d-flex justify-content-end mb-3"><a href="{{ route('DummyVariable.create') }}" class="btn btn-info">Create</a></div>

<table class="table table-bordered">
<thead>
<tr>
<th>id</th>
DummyHeaderTable
<th>Action</th>
<th scope='col'>id</th>
DummyHeaderTable
<th scope='col'>Action</th>
</tr>
</thead>
<tbody>
@foreach(DummyCreateVariable$ as DummyCreateVariableSing$)

<tr>
<td>{{ DummyCreateVariableSing$->id }}</td>
DummyIndexTable
DummyIndexTable
<td>
<div class="d-flex gap-2">
<a href="{{ route('DummyVariable.show', [DummyCreateVariableSing$->id]) }}" class="btn btn-info">Show</a>
<a href="{{ route('DummyVariable.edit', [DummyCreateVariableSing$->id]) }}" class="btn btn-primary">Edit</a>
{!! Form::open(['method' => 'DELETE','route' => ['DummyVariable.destroy', DummyCreateVariableSing$->id]]) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
{!! html()->form('DELETE', route('DummyVariable.destroy', DummyCreateVariableSing$->id))->open() !!}
{!! html()->submit('Delete')->class('btn btn-danger') !!}
{!! html()->form()->close() !!}
</div>
</td>
</tr>

@endforeach
</tbody>
</table>

@stop
10 changes: 5 additions & 5 deletions src/stubs/default-theme/livewire/index-datatable.stub
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
<thead>
<tr>
<th>id</th>
DummyHeaderTable
DummyHeaderTable
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach(DummyCreateVariable$ as DummyCreateVariableSing$)
<tr>
<td>{{ DummyCreateVariableSing$->id }}</td>
DummyIndexTable
DummyIndexTable
<td>
<div class="d-flex gap-2">
<a href="{{ route('DummyVariable.show', [DummyCreateVariableSing$->id]) }}" class="btn btn-info">Show</a>
<a href="{{ route('DummyVariable.edit', [DummyCreateVariableSing$->id]) }}" class="btn btn-primary">Edit</a>
{!! Form::open(['method' => 'DELETE','route' => ['DummyVariable.destroy', DummyCreateVariableSing$->id]]) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
{!! html()->form('DELETE', route('DummyVariable.destroy', DummyCreateVariableSing$->id))->open() !!}
{!! html()->submit('Delete')->class('btn btn-danger') !!}
{!! html()->form()->close() !!}
</div>
</td>
</tr>
Expand Down
14 changes: 7 additions & 7 deletions tests/Console/resultsOk/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
</div>
@endif

{!! Form::open(['route' => 'posts.store']) !!}
{!! html()->form('POST', route('posts.store'))->open() !!}

<div class="mb-3">
{{ Form::label('title', 'Title', ['class'=>'form-label']) }}
{{ Form::text('title', null, array('class' => 'form-control')) }}
{{ html()->label('Title', 'title') }}
{{ html()->text('title', null) }}
</div>
<div class="mb-3">
{{ Form::label('url', 'Url', ['class'=>'form-label']) }}
{{ Form::text('url', null, array('class' => 'form-control')) }}
{{ html()->label('Url', 'url') }}
{{ html()->text('url', null) }}
</div>


{{ Form::submit('Create', array('class' => 'btn btn-primary')) }}
{{ html()->submit('Create') }}

{{ Form::close() }}
{{ html()->form()->close() }}


@stop
14 changes: 7 additions & 7 deletions tests/Console/resultsOk/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
</div>
@endif

{{ Form::model($post, array('route' => array('posts.update', $post->id), 'method' => 'PUT')) }}
{{ html()->form()->modelform($post, 'PUT', route('posts.update', $post->id)) }}

<div class="mb-3">
{{ Form::label('title', 'Title', ['class'=>'form-label']) }}
{{ Form::text('title', null, array('class' => 'form-control')) }}
{{ html()->label('Title', 'title') }}
{{ html()->text('title', null) }}
</div>
<div class="mb-3">
{{ Form::label('url', 'Url', ['class'=>'form-label']) }}
{{ Form::text('url', null, array('class' => 'form-control')) }}
{{ html()->label('Url', 'url') }}
{{ html()->text('url', null) }}
</div>

{{ Form::submit('Edit', array('class' => 'btn btn-primary')) }}
{{ html()->submit('Edit') }}

{{ Form::close() }}
{{ html()->form()->close() }}
@stop
6 changes: 3 additions & 3 deletions tests/Console/resultsOk/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
<div class="d-flex gap-2">
<a href="{{ route('posts.show', [$post->id]) }}" class="btn btn-info">Show</a>
<a href="{{ route('posts.edit', [$post->id]) }}" class="btn btn-primary">Edit</a>
{!! Form::open(['method' => 'DELETE','route' => ['posts.destroy', $post->id]]) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
{!! html()->form('DELETE', route('posts.destroy', $post->id))->open() !!}
{!! html()->submit('Delete') !!}
{!! html()->form()->close() !!}
</div>
</td>
</tr>
Expand Down
6 changes: 3 additions & 3 deletions tests/Console/resultsOk/post-datatable.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
<div class="d-flex gap-2">
<a href="{{ route('posts.show', [$post->id]) }}" class="btn btn-info">Show</a>
<a href="{{ route('posts.edit', [$post->id]) }}" class="btn btn-primary">Edit</a>
{!! Form::open(['method' => 'DELETE','route' => ['posts.destroy', $post->id]]) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
{!! html()->form('DELETE',route('posts.destroy', $post->id))->open() !!}
{!! html()->form()->submit('Delete') !!}
{!! html()->form()->close() !!}
</div>
</td>
</tr>
Expand Down