Skip to content
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

128 beui create and edit taxonomy #174

Merged
merged 5 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<?php

namespace App\Domains\TaxonomyTerms\Models;
namespace App\Domains\Taxonomy\Models;

use App\Domains\Auth\Models\User;
use Database\Factories\TaxonomyTermsFactory;
use Database\Factories\TaxonomyTermFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Traits\LogsActivity;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use App\Domains\TaxonomyTerms\Models\Traits\Scope\TaxonomyTermsScope;

/**
* Class TaxonomyTerms.
* Class TaxonomyTerm.
*/
class TaxonomyTerms extends Model
class TaxonomyTerm extends Model
{
use TaxonomyTermsScope,
HasFactory,
use HasFactory,
LogsActivity;


Expand Down Expand Up @@ -46,6 +44,6 @@ public function user()
*/
protected static function newFactory()
{
return TaxonomyTermsFactory::new();
return TaxonomyTermFactory::new();
}
}

This file was deleted.

22 changes: 0 additions & 22 deletions app/Domains/TaxonomyTerms/Services/TaxonomyTermsService.php

This file was deleted.

46 changes: 41 additions & 5 deletions app/Http/Controllers/Backend/TaxonomyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
use App\Domains\Taxonomy\Models\Taxonomy;

Expand Down Expand Up @@ -31,7 +32,22 @@ public function create()
*/
public function store(Request $request)
{

$validatedData =$request->validate([
'code' => 'required|unique:taxonomies',
'name' => 'required',
'description' => 'nullable',
]);

try{
$taxonomy = new Taxonomy($validatedData);
$taxonomy->properties = $request->properties;
$taxonomy->created_by = Auth::user()->id;
$taxonomy->save();
return redirect()->route('dashboard.taxonomy.index')->with('Success', 'Taxonomy created successfully');
}catch (\Exception $ex) {
Log::error('Failed to create taxonomy', ['error' => $ex->getMessage()]);
return abort(500);
}
}
/**
* Show the form for editing the specified resource.
Expand All @@ -41,13 +57,17 @@ public function store(Request $request)
*/
public function edit(Taxonomy $taxonomy)
{
try{
return view('backend.taxonomy.edit', ['taxonomy' => $taxonomy]);
}catch (\Exception $ex) {
Log::error('Failed to load taxonomy edit page', ['error' => $ex->getMessage()]);
try {
return view('backend.taxonomy.edit', [
'taxonomy' => $taxonomy,
]);
} catch (\Exception $ex) {
Log::error('Failed to load taxonomy edit page', ['error' => $ex->getMessage()]);
return abort(500);
}
}


/**
* Update the specified resource in storage.
*
Expand All @@ -57,6 +77,22 @@ public function edit(Taxonomy $taxonomy)
*/
public function update(Request $request, Taxonomy $taxonomy)
{
$data = $request->validate([
'code' => 'required',
'name' => 'required',
'description' => 'nullable',
]);

try{
$taxonomy->update($data);
$taxonomy->properties = $request->properties;
$taxonomy->updated_by = Auth::user()->id;
$taxonomy->save();
return redirect()->route('dashboard.taxonomy.index')->with('Success', 'Taxonomy updated successfully');
}catch (\Exception $ex) {
Log::error('Failed to update taxonomy', ['error' => $ex->getMessage()]);
return abort(500);
}

}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use App\Http\Controllers\Controller;
use App\Domains\TaxonomyTerms\Models\TaxonomyTerms;
use App\Domains\Taxonomy\Models\TaxonomyTerm;

class TaxonomyTermsController extends Controller
class TaxonomyTermController extends Controller
{
/**
* Show the form for creating a new resource.
Expand All @@ -17,7 +17,7 @@ class TaxonomyTermsController extends Controller
public function create()
{
try{
return view('backend.taxonomyTerms.create');
return view('backend.taxonomy.terms.create');
}catch (\Exception $ex) {
Log::error('Failed to load taxonomy terms creation page', ['error' => $ex->getMessage()]);
return abort(500);
Expand All @@ -36,56 +36,55 @@ public function store(Request $request)
/**
* Show the form for editing the specified resource.
*
* @param \App\Domains\TaxonomyTerms\Models\TaxonomyTerms $taxonomyTerms
* @param \App\Domains\TaxonomyTerm\Models\TaxonomyTerm $taxonomyTerm
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*/
public function edit(TaxonomyTerms $taxonomyTerms)
public function edit(TaxonomyTerm $taxonomyTerm)
{
try{
return view('backend.taxonomyTerms.edit', ['taxonomyTerms' => $taxonomyTerms]);
return view('backend.taxonomy.terms.edit', ['taxonomyTerm' => $taxonomyTerm]);
}catch (\Exception $ex) {
Log::error('Failed to load taxonomy terms edit page', ['error' => $ex->getMessage()]);
Log::error('Failed to load taxonomy term edit page', ['error' => $ex->getMessage()]);
return abort(500);
}
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Domains\TaxonomyTerms\Models\TaxonomyTerms $taxonomyTerms
* @param \App\Domains\TaxonomyTerm\Models\TaxonomyTerm $taxonomyTerm
* @return \Illuminate\Http\RedirectResponse
*/
public function update(Request $request, TaxonomyTerms $taxonomyTerms)
public function update(Request $request, TaxonomyTerm $taxonomyTerm)
{

}
/**
* Confirm to delete the specified resource from storage.
*
* @param \App\Domains\TaxonomyTerms\Models\TaxonomyTerms $taxonomyTerms
* @param \App\Domains\TaxonomyTerm\Models\TaxonomyTerm $taxonomyTerm
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*/
public function delete(TaxonomyTerms $taxonomyTerms)
public function delete(TaxonomyTerm $taxonomyTerm)
{
return view('backend.taxonomyTerms.delete', compact('taxonomyTerms'));
return view('backend.taxonomy.terms.delete', compact('taxonomyTerm'));
}


/**
* Remove the specified resource from storage.
*
* @param \App\Domains\TaxonomyTerms\Models\TaxonomyTerms $taxonomyTerms
* @param \App\Domains\TaxonomyTerm\Models\TaxonomyTerm $taxonomyTerm
* @return \Illuminate\Http\RedirectResponse|null
*/
public function destroy(TaxonomyTerms $taxonomyTerms)
public function destroy(TaxonomyTerm $taxonomyTerm)
{
try {
$taxonomyTerms->delete();
return redirect()->route('dashboard.taxonomyTerms.index')->with('Success', 'Taxonomy term was deleted !');
$taxonomyTerm->delete();
return redirect()->route('dashboard.taxonomy.terms.index')->with('Success', 'Taxonomy term was deleted !');
} catch (\Exception $ex) {
Log::error('Failed to delete taxonomy term', ['taxonomyTerms_id' => $taxonomyTerms->id, 'error' => $ex->getMessage()]);
Log::error('Failed to delete taxonomy term', ['taxonomyTerm_id' => $taxonomyTerm->id, 'error' => $ex->getMessage()]);
return abort(500);
}
}
}

}
4 changes: 3 additions & 1 deletion app/Http/Livewire/Backend/TaxonomyTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function columns(): array
->sortable(),
Column::make("Created at", "created_at")
->sortable(),
Column::make("Updated at", "updated_at")
->sortable(),
Column::make("Actions")
];
}
Expand All @@ -39,7 +41,7 @@ public function query(): Builder

public function rowView(): string
{
return 'backend.taxonomies.index-table-row';
return 'backend.taxonomy.index-table-row';
}
}

Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<?php

namespace Database\Factories;
use App\Domains\TaxonomyTerms\Models\TaxonomyTerms;
use App\Domains\Taxonomy\Models\TaxonomyTerm;
use App\Domains\Auth\Models\User;



use Illuminate\Database\Eloquent\Factories\Factory;

class TaxonomyTermsFactory extends Factory
class TaxonomyTermFactory extends Factory
{



protected $model = TaxonomyTerms::class;
protected $model = TaxonomyTerm::class;

/**
* Define the model's default state.
Expand Down
60 changes: 0 additions & 60 deletions resources/views/backend/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,66 +58,6 @@
<script src="{{ mix('js/backend.js') }}"></script>
@stack('after-scripts')

<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<script>
var toolbarOptions = [
['bold', 'italic', 'underline', 'strike'], // toggled buttons

[{
'header': 1
}, {
'header': 2
}], // custom button values
[{
'list': 'ordered'
}, {
'list': 'bullet'
}],
[{
'script': 'sub'
}, {
'script': 'super'
}], // superscript/subscript
[{
'indent': '-1'
}, {
'indent': '+1'
}], // outdent/indent

[{
'size': ['small', false, 'large', 'huge']
}], // custom dropdown
[{
'header': [1, 2, 3, 4, 5, 6, false]
}],

[{
'color': []
}, {
'background': []
}], // dropdown with defaults from theme
[{
'align': []
}],

['clean'] // remove formatting button
];

var quill = new Quill('#editor-container', {
theme: 'snow',
modules: {
toolbar: toolbarOptions
}
});

document.getElementById('submit-button').addEventListener('click', function(event) {
// Get Quill content
var quillContent = quill.root.innerHTML;
// Populate hidden form field with quill data
var description = document.querySelector('textarea[name=description]');
description.value = quillContent;
});
</script>
</body>

</html>
Loading
Loading