mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-05-29 11:30:50 +08:00
Added page editing
This commit is contained in:
@ -4,11 +4,29 @@ namespace Oxbow\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Oxbow\Http\Requests;
|
||||
use Oxbow\Http\Controllers\Controller;
|
||||
use Oxbow\Repos\BookRepo;
|
||||
use Oxbow\Repos\PageRepo;
|
||||
|
||||
class PageController extends Controller
|
||||
{
|
||||
|
||||
protected $pageRepo;
|
||||
protected $bookRepo;
|
||||
|
||||
/**
|
||||
* PageController constructor.
|
||||
* @param $pageRepo
|
||||
* @param $bookRepo
|
||||
*/
|
||||
public function __construct(PageRepo $pageRepo, BookRepo $bookRepo)
|
||||
{
|
||||
$this->pageRepo = $pageRepo;
|
||||
$this->bookRepo = $bookRepo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
@ -22,56 +40,88 @@ class PageController extends Controller
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param $bookSlug
|
||||
* @return Response
|
||||
*/
|
||||
public function create()
|
||||
public function create($bookSlug)
|
||||
{
|
||||
//
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
return view('pages/create', ['book' => $book]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Request $request
|
||||
* @param $bookSlug
|
||||
* @return Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
public function store(Request $request, $bookSlug)
|
||||
{
|
||||
//
|
||||
$this->validate($request, [
|
||||
'name' => 'required|string|max:255',
|
||||
'html' => 'required|string',
|
||||
'priority' => 'integer'
|
||||
]);
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$page = $this->pageRepo->newFromInput($request->all());
|
||||
$slug = Str::slug($page->name);
|
||||
while($this->pageRepo->countBySlug($slug, $book->id) > 0) {
|
||||
$slug .= '1';
|
||||
}
|
||||
$page->slug =$slug;
|
||||
$page->book_id = $book->id;
|
||||
$page->text = strip_tags($page->html);
|
||||
$page->save();
|
||||
return redirect($page->getUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @param $bookSlug
|
||||
* @param $pageSlug
|
||||
* @return Response
|
||||
*/
|
||||
public function show($id)
|
||||
public function show($bookSlug, $pageSlug)
|
||||
{
|
||||
//
|
||||
$page = $this->pageRepo->getBySlug($pageSlug);
|
||||
return view('pages/show', ['page' => $page]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @param $bookSlug
|
||||
* @param $pageSlug
|
||||
* @return Response
|
||||
*/
|
||||
public function edit($id)
|
||||
public function edit($bookSlug, $pageSlug)
|
||||
{
|
||||
//
|
||||
$page = $this->pageRepo->getBySlug($pageSlug);
|
||||
return view('pages/edit', ['page' => $page]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @param Request $request
|
||||
* @param $bookSlug
|
||||
* @param $pageSlug
|
||||
* @return Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
public function update(Request $request, $bookSlug, $pageSlug)
|
||||
{
|
||||
//
|
||||
$page = $this->pageRepo->getBySlug($pageSlug);
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$page->fill($request->all());
|
||||
$slug = Str::slug($page->name);
|
||||
while($this->pageRepo->countBySlug($slug, $book->id) > 0 && $slug != $pageSlug) {
|
||||
$slug .= '1';
|
||||
}
|
||||
$page->text = strip_tags($page->html);
|
||||
$page->save();
|
||||
return redirect($page->getUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user