Skip to content

Commit

Permalink
Merge remote-tracking branch 'fork/unique-taxo-label-parent' into dev…
Browse files Browse the repository at this point in the history
…elopment
  • Loading branch information
ketan404 committed Dec 7, 2023
2 parents ad5fc80 + 0b4dd13 commit 5018c5b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
14 changes: 11 additions & 3 deletions app/Http/Controllers/TaxonomyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ public function add($id)

public function addstore(TaxonomyRequest $request, $id)
{
try{
$taxonomy_new = new Taxonomy();
$taxonomy_new ->label = $request->label;
$taxonomy_new->parent_id = $id;
$taxonomy_new ->save();

Session::flash('alert-success', 'Taxonomy successfully added.');
Session::flash('alert-success', 'Taxonomy successfully added.');
}
catch(\Exception $e){
Session::flash('alert-error', $e->getMessage());
}
return redirect()->route('taxonomies.index');
}

Expand All @@ -57,12 +61,16 @@ public function edit($id)

public function update(TaxonomyRequest $request, $id)
{
try{
$taxonomies = Taxonomy::find($id);
$taxonomies ->parent_id = $request->parent_id;
$taxonomies ->label = $request->label;
$taxonomies ->save();

Session::flash('alert-success', 'Taxonomy successfully updated.');
}
catch(\Exception $e){
Session::flash('alert-error', $e->getMessage());
}
return redirect()->route('taxonomies.index')->withStatus(__('Taxonomy successfully updated.'));
}

Expand Down
32 changes: 32 additions & 0 deletions database/migrations/2023_12_07_102246_unique-taxo-label-parent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class UniqueTaxoLabelParent extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('taxonomies', function (Blueprint $table) {
$table->unique(['label','parent_id']);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('taxonomies', function (Blueprint $table) {
$table->dropUnique(['label','parent_id']);
});
}
}

0 comments on commit 5018c5b

Please sign in to comment.