Permalink
Browse files

Admin - manage tags with unique slug (new package)

  • Loading branch information...
bpocallaghan committed Jul 8, 2017
1 parent 102fde3 commit d879c6c9a0fa0ccdd076848e9b9d19bb4d9d2879
@@ -0,0 +1,101 @@
<?php
namespace App\Http\Controllers\Admin;
use Redirect;
use App\Http\Requests;
use App\Models\Tag;
use Illuminate\Http\Request;
use App\Http\Controllers\Admin\AdminController;
class TagsController extends AdminController
{
/**
* Display a listing of tag.
*
* @return Response
*/
public function index()
{
save_resource_url();
return $this->view('tags.index')->with('items', Tag::all());
}
/**
* Show the form for creating a new tag.
*
* @return Response
*/
public function create()
{
return $this->view('tags.add_edit');
}
/**
* Store a newly created tag in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$this->validate($request, Tag::$rules, Tag::$messages);
$row = $this->createEntry(Tag::class, $request->only('name'));
return redirect_to_resource();
}
/**
* Display the specified tag.
*
* @param Tag $tag
* @return Response
*/
public function show(Tag $tag)
{
return $this->view('tags.show')->with('item', $tag);
}
/**
* Show the form for editing the specified tag.
*
* @param Tag $tag
* @return Response
*/
public function edit(Tag $tag)
{
return $this->view('tags.add_edit')->with('item', $tag);
}
/**
* Update the specified tag in storage.
*
* @param Tag $tag
* @param Request $request
* @return Response
*/
public function update(Tag $tag, Request $request)
{
$this->validate($request, Tag::$rules, Tag::$messages);
$this->updateEntry($tag, $request->only('name'));
return redirect_to_resource();
}
/**
* Remove the specified tag from storage.
*
* @param Tag $tag
* @param Request $request
* @return Response
*/
public function destroy(Tag $tag, Request $request)
{
$this->deleteEntry($tag, $request);
return redirect_to_resource();
}
}
@@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Titan\Models\TitanCMSModel;
use Bpocallaghan\Sluggable\HasSlug;
use Illuminate\Database\Eloquent\SoftDeletes;
class Tag extends TitanCMSModel
{
use SoftDeletes, HasSlug;
protected $table = 'tags';
protected $guarded = ['id'];
/**
* Validation rules for this model
*/
static public $rules = [
'name' => 'required|min:2:max:255',
];
}
@@ -9,6 +9,7 @@
"bpocallaghan/alert": "^1.0",
"bpocallaghan/impersonate": "^0.1.0",
"bpocallaghan/notify": "^2.0",
"bpocallaghan/sluggable": "^1.0",
"bpocallaghan/titan": "^0.2.3",
"google/recaptcha": "^1.1",
"intervention/image": "^2.3",
Oops, something went wrong.

0 comments on commit d879c6c

Please sign in to comment.