This commit is contained in:
Chris 2019-06-13 15:40:26 +01:00
parent d79202ed87
commit 1419882455
3 changed files with 35 additions and 2 deletions

View file

@ -125,6 +125,7 @@ class ItemController extends Controller
{
//
$data['tags'] = Item::ofType('tag')->orderBy('title', 'asc')->pluck('title', 'id');
$data['tags']->prepend('Home dashboard', 0);
$data['current_tags'] = [];
return view('items.create', $data);
@ -200,8 +201,10 @@ class ItemController extends Controller
// Get the item
$data['item'] = Item::find($id);
$data['tags'] = Item::ofType('tag')->orderBy('title', 'asc')->pluck('title', 'id');
$data['current_tags'] = $data['item']->parents;
$data['tags']->prepend('Home dashboard', 0);
$data['current_tags'] = $data['item']->tags();
//$data['current_tags'] = $data['item']->parent;
//die(print_r($data['current_tags']));
// show the edit form and pass the nerd
return view('items.edit', $data);
}

View file

@ -7,6 +7,7 @@ use Symfony\Component\ClassLoader\ClassMapGenerator;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Builder;
use App\User;
use App\ItemTag;
use App\Application;
class Item extends Model
@ -70,6 +71,25 @@ class Item extends Model
}
public function tags()
{
$id = $this->id;
$tags = ItemTag::select('tag_id')->where('item_id', $id)->pluck('tag_id')->toArray();
$tagdetails = Item::select('id', 'title', 'url', 'pinned')->whereIn('id', $tags)->get();
//print_r($tags);
if(in_array(0, $tags)) {
$details = new Item([
"id" => 0,
"title" => 'Home dashboard',
"url" => '',
"pinned" => 1
]);
$tagdetails->prepend($details);
}
return $tagdetails;
}
public function parents()
{
return $this->belongsToMany('App\Item', 'item_tag', 'item_id', 'tag_id');

10
app/ItemTag.php Normal file
View file

@ -0,0 +1,10 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Relations\Pivot;
class ItemTag extends Pivot
{
}