Skip to content

Commit

Permalink
Fix routing problem
Browse files Browse the repository at this point in the history
  • Loading branch information
reziamini committed Jul 18, 2021
1 parent 617ed7d commit 0d65404
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 35 deletions.
12 changes: 6 additions & 6 deletions resources/views/layouts/child-sidebar-menu.blade.php
@@ -1,20 +1,20 @@
<li class="list-divider"></li>
<li class="nav-small-cap"><span class="hide-menu">{{ __('CRUD Menu') }}</span></li>
@foreach(\EasyPanel\Models\CRUD::active() as $crud)
<li class='sidebar-item @isActive([getRouteName().".{$crud->name}.read", getRouteName().".{$crud->name}.create", getRouteName().".{$crud->name}.update"], "selected")'>
<li class='sidebar-item @isActive([getRouteName().".{$crud->route}.read", getRouteName().".{$crud->route}.create", getRouteName().".{$crud->route}.update"], "selected")'>
<a class='sidebar-link has-arrow' href="javascript:void(0)" aria-expanded="false">
<i data-feather="{{ get_icon($crud->name) }}" class="feather-icon"></i>
<span class="hide-menu">{{ __(\Illuminate\Support\Str::plural(ucfirst($crud->name))) }}</span>
</a>
<ul aria-expanded="false" class="collapse first-level base-level-line">
<li class="sidebar-item @isActive(getRouteName().'.'.$crud->name.'.read')">
<a href="@route(getRouteName().'.'.$crud->name.'.read')" class="sidebar-link @isActive(getRouteName().'.'.$crud->name.'.read')">
<li class="sidebar-item @isActive(getRouteName().'.'.$crud->route.'.read')">
<a href="@route(getRouteName().'.'.$crud->route.'.read')" class="sidebar-link @isActive(getRouteName().'.'.$crud->route.'.read')">
<span class="hide-menu"> {{ __('List') }} </span>
</a>
</li>
@if(getCrudConfig($crud->name))
<li class="sidebar-item @isActive(getRouteName().'.'.$crud->name.'.create')">
<a href="@route(getRouteName().'.'.$crud->name.'.create')" class="sidebar-link @isActive(getRouteName().'.'.$crud->name.'.create')">
@if(getCrudConfig($crud->name)->create)
<li class="sidebar-item @isActive(getRouteName().'.'.$crud->route.'.create')">
<a href="@route(getRouteName().'.'.$crud->route.'.create')" class="sidebar-link @isActive(getRouteName().'.'.$crud->route.'.create')">
<span class="hide-menu"> {{ __('Create') }} </span>
</a>
</li>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/livewire/crud/single.blade.php
Expand Up @@ -10,8 +10,8 @@

<div x-show="deleteModal" class="cs-modal animate__animated animate__fadeIn">
<div class="bg-white shadow rounded p-5" @click.away="deleteModal = false" >
<h5 class="pb-2 border-bottom">{{ __('DeleteTitle', ['name' => __('Article') ]) }}</h5>
<p>{{ __('DeleteMessage', ['name' => __('Article') ]) }}</p>
<h5 class="pb-2 border-bottom">{{ __('DeleteTitle', ['name' => __('CRUD') ]) }}</h5>
<p>{{ __('DeleteMessage', ['name' => __('CRUD') ]) }}</p>
<div class="mt-5 d-flex justify-content-between">
<a wire:click.prevent="delete" class="text-white btn btn-success shadow">{{ __('Yes, Delete it.') }}</a>
<a @click.prevent="deleteModal = false" class="text-white btn btn-danger shadow">{{ __('No, Cancel it.') }}</a>
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/stub/blade/create.blade.stub
Expand Up @@ -4,7 +4,7 @@
<div class="px-2 mt-4">
<ul class="breadcrumb mt-3 py-3 px-4 rounded" style="background-color: #e9ecef!important;">
<li class="breadcrumb-item"><a href="@route(getRouteName().'.home')" class="text-decoration-none">{{ __('Dashboard') }}</a></li>
<li class="breadcrumb-item"><a href="@route(getRouteName().'.{{ model }}.read')" class="text-decoration-none">{{ __(\Illuminate\Support\Str::plural('{{ modelName }}')) }}</a></li>
<li class="breadcrumb-item"><a href="@route(getRouteName().'.'.crud('{{ model }}')->route.'.read')" class="text-decoration-none">{{ __(\Illuminate\Support\Str::plural('{{ modelName }}')) }}</a></li>
<li class="breadcrumb-item active">{{ __('Create') }}</li>
</ul>
</div>
Expand All @@ -18,7 +18,7 @@

<div class="card-footer">
<button type="submit" class="btn btn-info ml-4">{{ __('Create') }}</button>
<a href="@route(getRouteName().'.{{ model }}.read')" class="btn btn-default float-left">{{ __('Cancel') }}</a>
<a href="@route(getRouteName().'.'.crud('{{ model }}')->route.'.read')" class="btn btn-default float-left">{{ __('Cancel') }}</a>
</div>
</form>
</div>
2 changes: 1 addition & 1 deletion src/Commands/stub/blade/read.blade.stub
Expand Up @@ -14,7 +14,7 @@
<div class="row justify-content-between mt-4 mb-4">
@if(getCrudConfig('{{ model }}')->create)
<div class="col-md-4 right-0">
<a href="@route(getRouteName().'.{{ model }}.create')" class="btn btn-success">{{ __('CreateTitle', ['name' => __('{{ modelName }}') ]) }}</a>
<a href="@route(getRouteName().'.'.crud('{{ model }}')->route.'.create')" class="btn btn-success">{{ __('CreateTitle', ['name' => __('{{ modelName }}') ]) }}</a>
</div>
@endif
@if(getCrudConfig('{{ model }}')->searchable())
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/stub/blade/single.blade.stub
Expand Up @@ -4,7 +4,7 @@
<td>

@if(getCrudConfig('{{ model }}')->update)
<a href="@route(getRouteName().'.{{ model }}.update', ['{{ model }}' => ${{ model }}->id])" class="btn text-primary mt-1">
<a href="@route(getRouteName().'.'.crud('{{ model }}')->route.'.update', ['{{ model }}' => ${{ model }}->id])" class="btn text-primary mt-1">
<i class="icon-pencil"></i>
</a>
@endif
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/stub/blade/update.blade.stub
Expand Up @@ -4,7 +4,7 @@
<div class="px-2 mt-4">
<ul class="breadcrumb mt-3 py-3 px-4 rounded" style="background-color: #e9ecef!important;">
<li class="breadcrumb-item"><a href="@route(getRouteName().'.home')" class="text-decoration-none">{{ __('Dashboard') }}</a></li>
<li class="breadcrumb-item"><a href="@route(getRouteName().'.{{ model }}.read')" class="text-decoration-none">{{ __(\Illuminate\Support\Str::plural('{{ modelName }}')) }}</a></li>
<li class="breadcrumb-item"><a href="@route(getRouteName().'.'.crud('{{ model }}')->route.'.read')" class="text-decoration-none">{{ __(\Illuminate\Support\Str::plural('{{ modelName }}')) }}</a></li>
<li class="breadcrumb-item active">{{ __('Update') }}</li>
</ul>
</div>
Expand All @@ -20,7 +20,7 @@

<div class="card-footer">
<button type="submit" class="btn btn-info ml-4">{{ __('Update') }}</button>
<a href="@route(getRouteName().'.{{ model }}.read')" class="btn btn-default float-left">{{ __('Cancel') }}</a>
<a href="@route(getRouteName().'.'.crud('{{ model }}')->route.'.read')" class="btn btn-default float-left">{{ __('Cancel') }}</a>
</div>
</form>
</div>
27 changes: 6 additions & 21 deletions src/helpers.php
Expand Up @@ -29,6 +29,12 @@ function getCrudConfig($name){
}
}

if(! function_exists('crud')) {
function crud($name){
return \EasyPanel\Models\CRUD::query()->where('name', $name)->first();
}
}

if(! function_exists('get_icon')) {
function get_icon($type){
$array = [
Expand All @@ -55,24 +61,3 @@ function get_icon($type){
return $val ?? 'grid';
}
}

if(! function_exists('registerActionRoutes')){
function registerActionRoutes($prefix, $component, $crudConfig)
{
Route::prefix($prefix)->name("$prefix.")->group(function () use ($component, $crudConfig) {

if(@class_exists("$component\\Read")) {
Route::get('/', "$component\\Read")->name('read');
}

if (@$crudConfig->create and @class_exists("$component\\Create")) {
Route::get('/create', "$component\\Create")->name('create');
}

if (@$crudConfig->update and @class_exists("$component\\Update")) {
Route::get('/update/{' . $action . '}', "$component\\Update")->name('update');
}

});
}
}

0 comments on commit 0d65404

Please sign in to comment.