Commit 60ce1613 authored by Vipul Basapati's avatar Vipul Basapati

Refactored Faqs Module

parent 86e360dd
......@@ -13,7 +13,6 @@ class Kernel extends ConsoleKernel
* @var array
*/
protected $commands = [
'App\Console\Commands\ModuleGenerator',
];
/**
......
<?php
namespace App\Http\Controllers\Backend\Faqs;
use App\Models\Faqs\Faq;
use App\Http\Controllers\Controller;
use App\Repositories\Backend\Faqs\FaqsRepository;
use App\Http\Requests\Backend\Faqs\EditFaqsRequest;
use App\Http\Requests\Backend\Faqs\ManageFaqsRequest;
class FaqStatusController extends Controller
{
protected $faq;
/**
* @param \App\Repositories\Backend\Faqs\FaqsRepository $faq
*/
public function __construct(FaqsRepository $faq)
{
$this->faq = $faq;
}
/**
* @param \App\Models\Faqs\Faq $Faq
* @param $status
* @param \App\Http\Requests\Backend\Faqs\ManageFaqsRequest $request
*
* @return mixed
*/
public function store(Faq $faq, $status, EditFaqsRequest $request)
{
$this->faq->mark($faq, $status);
return redirect()
->route('admin.faqs.index')
->with('flash_success', trans('alerts.backend.faqs.updated'));
}
}
\ No newline at end of file
......@@ -14,34 +14,30 @@ use App\Repositories\Backend\Faqs\FaqsRepository;
class FaqsController extends Controller
{
/**
* @var FaqsRepository
*/
protected $faqs;
protected $faq;
/**
* @param FaqsRepository $faqs
* @param \App\Repositories\Backend\Faqs\FaqsRepository $faq
*/
public function __construct(FaqsRepository $faqs)
public function __construct(FaqsRepository $faq)
{
$this->faqs = $faqs;
$this->faq = $faq;
}
/**
* Display a listing of the resource.
* @param \App\Http\Requests\Backend\Faqs\ManageFaqsRequest $request
*
* @return \Illuminate\Http\Response
*/
public function index(ManageFaqsRequest $request)
{
//Status array
$status = [1 => 'Active', 0 => 'Inactive'];
return view('backend.faqs.index')->withStatus($status);
return view('backend.faqs.index');
}
/**
* Show the form for creating a new resource.
* @param \App\Http\Requests\Backend\Faqs\CreateFaqsRequest $request
*
* @return \Illuminate\Http\Response
*/
......@@ -52,8 +48,7 @@ class FaqsController extends Controller
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Http\Requests\Backend\Faqs\StoreFaqsRequest $request
*
* @return \Illuminate\Http\Response
*/
......@@ -61,39 +56,32 @@ class FaqsController extends Controller
{
$input = $request->all();
$this->faqs->create($input);
$this->faq->create($input);
return redirect()->route('admin.faqs.index')->withFlashSuccess(trans('alerts.backend.faqs.created'));
}
/**
* Display the specified resource.
*
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function show($id)
{
return redirect()
->route('admin.faqs.index')
->with('flash_success', trans('alerts.backend.faqs.created'));
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @param \App\Models\Faqs\Faq $faq
* @param \App\Http\Requests\Backend\Faqs\EditFaqsRequest $request
*
* @return \Illuminate\Http\Response
*/
public function edit(Faq $faq, EditFaqsRequest $request)
{
return view('backend.faqs.edit')->withItem($faq);
return view('backend.faqs.edit')
->with('faq', $faq);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @param \App\Http\Requests\Backend\Faqs\UpdateFaqsRequest $request
* @param \App\Models\Faqs\Faq $id
*
* @return \Illuminate\Http\Response
*/
......@@ -101,37 +89,27 @@ class FaqsController extends Controller
{
$input = $request->all();
$this->faqs->update($faq, $input);
$this->faq->update($faq, $input);
return redirect()->route('admin.faqs.index')->withFlashSuccess(trans('alerts.backend.faqs.updated'));
return redirect()
->route('admin.faqs.index')
->with('flash_success', trans('alerts.backend.faqs.updated'));
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @param \App\Models\Faqs\Faq $faq
* @param \App\Http\Requests\Backend\Faqs\DeleteFaqsRequest $request
*
* @return \Illuminate\Http\Response
*/
public function destroy(Faq $faq, DeleteFaqsRequest $request)
{
$this->faqs->delete($faq);
return redirect()->route('admin.faqs.index')->withFlashSuccess(trans('alerts.backend.faqs.deleted'));
}
/**
* @param Faq $Faq
* @param $status
* @param ManageFaqRequest $request
*
* @return mixed
*/
public function mark($id, $status, EditFaqsRequest $request)
{
$faq = Faq::find($id);
$this->faqs->mark($faq, $status);
$this->faq->delete($faq);
return redirect()->route('admin.faqs.index')->withFlashSuccess(trans('alerts.backend.faqs.updated'));
return redirect()
->route('admin.faqs.index')
->with('flash_success', trans('alerts.backend.faqs.deleted'));
}
}
......@@ -32,6 +32,6 @@ class Faq extends BaseModel
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->table = config('access.faqs_table');
$this->table = config('module.faqs.table');
}
}
......@@ -23,31 +23,27 @@ class FaqsRepository extends BaseRepository
{
return $this->query()
->select([
config('access.faqs_table').'.id',
config('access.faqs_table').'.question',
config('access.faqs_table').'.answer',
config('access.faqs_table').'.status',
config('access.faqs_table').'.created_at',
config('mdule.faqs.able').'.id',
config('odule.faqs.table').'.question',
config('module.faqs.table').'.answer',
config('module.faqs.table').'.status',
config('module.faqs.table').'.created_at',
]);
}
/**
* @param array $input
*
* @throws GeneralException
* @throws \App\Exceptions\GeneralException
*
* @return bool
*/
public function create(array $input)
{
$faq = self::MODEL;
$faq = new $faq();
$faq->question = $input['question'];
$faq->answer = $input['answer'];
$faq->status = isset($input['status']) ? $input['status'] : 0;
$input['status'] = isset($input['status']) ? 1 : 0;
//If faq saved successfully, then return true
if ($faq->save()) {
if (Faq::create($input)) {
return true;
}
......@@ -55,21 +51,19 @@ class FaqsRepository extends BaseRepository
}
/**
* @param Model $permission
* @param $input
* @param \App\Models\Faqs\Faq $faq
* @param array $input
*
* @throws GeneralException
* @throws \App\Exceptions\GeneralException
*
* return bool
*/
public function update(Model $faq, array $input)
public function update(Faq $faq, array $input)
{
$faq->question = $input['question'];
$faq->answer = $input['answer'];
$faq->status = isset($input['status']) ? $input['status'] : 0;
$input['status'] = isset($input['status']) ? 1 : 0;
//If faq updated successfully
if ($faq->save()) {
if ($faq->update($input)) {
return true;
}
......@@ -77,13 +71,13 @@ class FaqsRepository extends BaseRepository
}
/**
* @param Model $blog
* @param \App\Models\Faqs\Faq $faq
*
* @throws GeneralException
* @throws \App\Exceptions\GeneralException
*
* @return bool
*/
public function delete(Model $faq)
public function delete(Faq $faq)
{
if ($faq->delete()) {
return true;
......@@ -93,14 +87,14 @@ class FaqsRepository extends BaseRepository
}
/**
* @param Model $faq
* @param $status
* @param \App\Models\Faqs\Faq $faq
* @param string $status
*
* @throws GeneralException
* @throws \App\Exceptions\GeneralException
*
* @return bool
*/
public function mark(Model $faq, $status)
public function mark(Faq $faq, $status)
{
$faq->status = $status;
......
......@@ -17,5 +17,8 @@ return [
],
'blogs' => [
'table' => 'blogs'
],
'faqs' => [
'table' => 'faqs'
]
];
......@@ -10,7 +10,7 @@
@endsection
@section('content')
{{ Form::model($item, ['route' => ['admin.faqs.update', $item], 'class' => 'form-horizontal', 'role' => 'form', 'method' => 'PATCH', 'id' => 'edit-faqs']) }}
{{ Form::model($faq, ['route' => ['admin.faqs.update', $faq], 'class' => 'form-horizontal', 'role' => 'form', 'method' => 'PATCH', 'id' => 'edit-faqs']) }}
<div class="box box-success">
<div class="box-header with-border">
......
......@@ -21,8 +21,8 @@
<div class="col-lg-10">
<div class="control-group">
<label class="control control--checkbox">
@if(isset($item->status))
{{ Form::checkbox('status', 1, $item->status == 1 ? true :false) }}
@if(isset($faq->status))
{{ Form::checkbox('status', 1, $faq->status == 1 ? true :false) }}
@else
{{ Form::checkbox('status', 1, true) }}
@endif
......
......@@ -39,7 +39,7 @@
<a class="reset-data" href="javascript:void(0)"><i class="fa fa-times"></i></a>
</th>
<th>
{!! Form::select('status', $status, null, ["class" => "search-input-select form-control", "data-column" => 2, "placeholder" => trans('labels.backend.faqs.table.all')]) !!}
{!! Form::select('status', [1 => 'Active', 0 => 'InActive'], null, ["class" => "search-input-select form-control", "data-column" => 2, "placeholder" => trans('labels.backend.faqs.table.all')]) !!}
</th>
{{-- <th></th> --}}
<th></th>
......@@ -78,10 +78,10 @@
type: 'post'
},
columns: [
{data: 'question', name: '{{config('access.faqs_table')}}.question'},
{data: 'answer', name: '{{config('access.faqs_table')}}.answer'},
{data: 'status', name: '{{config('access.faqs_table')}}.status'},
{data: 'updated_at', name: '{{config('access.faqs_table')}}.updated_at'},
{data: 'question', name: '{{config('module.faqs.table')}}.question'},
{data: 'answer', name: '{{config('module.faqs.table')}}.answer'},
{data: 'status', name: '{{config('module.faqs.table')}}.status'},
{data: 'updated_at', name: '{{config('module.faqs.table')}}.updated_at'},
{data: 'actions', name: 'actions', searchable: false, sortable: false}
],
order: [[1, "asc"]],
......
......@@ -10,5 +10,5 @@ Route::group(['namespace' => 'Faqs'], function () {
Route::post('faqs/get', 'FaqsTableController')->name('faqs.get');
// Status
Route::get('faqs/{id}/mark/{status}', 'FaqsController@mark')->name('faqs.mark')->where(['status' => '[0,1]']);
Route::get('faqs/{faq}/mark/{status}', 'FaqStatusController@store')->name('faqs.mark')->where(['status' => '[0,1]']);
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment