Files

87 lines
2.3 KiB
PHP

<?php
namespace App\Http\Controllers\Admin\Contents;
use App\CMS\Contracts\Repositories\Content as ContentContract;
use App\Cms\Handlers\Interactions\Interaction;
use App\CMS\Interactions\Admin\Content\ChangeStatus;
use App\CMS\Interactions\Admin\Content\DeletePage;
use App\CMS\Interactions\Admin\Content\SetHomepage;
use App\Http\Controllers\Admin\Controller;
class ContentActions extends Controller
{
/**
* @var ContentContract
*/
private $content;
public function __construct(ContentContract $content)
{
$this->content = $content;
}
/**
* Method for changing page status
* This method is called in static page overview from quick actions. It checks if status is valid, if page exists
* and updates status.
*
* @param $id
* @param $status
*
* @return \Illuminate\Http\RedirectResponse
*/
public function changeStatus($id, $status)
{
$page = $this->content->getOne($id);
Interaction::handle(ChangeStatus::class, ['status' => $status], $page);
// redirect back to overview with info for user
return redirect()
->route('content.overview')
->with('success', trans('admin/contents.statusChanged'));
}
/**
* Delete page
*
* @param $id
*
* @return \Illuminate\Http\RedirectResponse
*/
public function delete($id)
{
$page = $this->content->getOne($id);
Interaction::handle(DeletePage::class, [], $page);
// redirect back to overview with info for user
return redirect()
->route('content.overview')
->with('success', trans('admin/contents.pageDeleted', [
'name' => $page->title
]));
}
/**
* Sets page as homepage
*
* @param $id
*
* @return \Illuminate\Http\RedirectResponse
*/
public function setHomepage($id)
{
$page = $this->content->getOne($id);
Interaction::handle(SetHomepage::class, [], $page);
// redirect back to overview with info for user
return redirect()
->back()
->with('success', trans('admin/contents.homepageSetup', [
'name' => $page->title,
'url' => $page->url
]));
}
}