initial
This commit is contained in:
parent
d79202ed87
commit
1419882455
|
@ -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);
|
||||
}
|
||||
|
|
20
app/Item.php
20
app/Item.php
|
@ -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
10
app/ItemTag.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
class ItemTag extends Pivot
|
||||
{
|
||||
|
||||
}
|
Loading…
Reference in a new issue