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

Refactored Faqs Module

parent 86e360dd
...@@ -13,7 +13,6 @@ class Kernel extends ConsoleKernel ...@@ -13,7 +13,6 @@ class Kernel extends ConsoleKernel
* @var array * @var array
*/ */
protected $commands = [ 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,35 +14,31 @@ use App\Repositories\Backend\Faqs\FaqsRepository; ...@@ -14,35 +14,31 @@ use App\Repositories\Backend\Faqs\FaqsRepository;
class FaqsController extends Controller class FaqsController extends Controller
{ {
/** protected $faq;
* @var FaqsRepository
*/
protected $faqs;
/** /**
* @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. * Display a listing of the resource.
* * @param \App\Http\Requests\Backend\Faqs\ManageFaqsRequest $request
*
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function index(ManageFaqsRequest $request) public function index(ManageFaqsRequest $request)
{ {
//Status array return view('backend.faqs.index');
$status = [1 => 'Active', 0 => 'Inactive'];
return view('backend.faqs.index')->withStatus($status);
} }
/** /**
* Show the form for creating a new resource. * Show the form for creating a new resource.
* * @param \App\Http\Requests\Backend\Faqs\CreateFaqsRequest $request
*
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function create(CreateFaqsRequest $request) public function create(CreateFaqsRequest $request)
...@@ -52,8 +48,7 @@ class FaqsController extends Controller ...@@ -52,8 +48,7 @@ class FaqsController extends Controller
/** /**
* Store a newly created resource in storage. * Store a newly created resource in storage.
* * @param \App\Http\Requests\Backend\Faqs\StoreFaqsRequest $request
* @param \Illuminate\Http\Request $request
* *
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
...@@ -61,39 +56,32 @@ class FaqsController extends Controller ...@@ -61,39 +56,32 @@ class FaqsController extends Controller
{ {
$input = $request->all(); $input = $request->all();
$this->faqs->create($input); $this->faq->create($input);
return redirect()->route('admin.faqs.index')->withFlashSuccess(trans('alerts.backend.faqs.created')); return redirect()
} ->route('admin.faqs.index')
->with('flash_success', trans('alerts.backend.faqs.created'));
/**
* Display the specified resource.
*
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function show($id)
{
} }
/** /**
* Show the form for editing the specified resource. * 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 * @return \Illuminate\Http\Response
*/ */
public function edit(Faq $faq, EditFaqsRequest $request) 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. * Update the specified resource in storage.
* *
* @param \Illuminate\Http\Request $request * @param \App\Http\Requests\Backend\Faqs\UpdateFaqsRequest $request
* @param int $id * @param \App\Models\Faqs\Faq $id
* *
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
...@@ -101,37 +89,27 @@ class FaqsController extends Controller ...@@ -101,37 +89,27 @@ class FaqsController extends Controller
{ {
$input = $request->all(); $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. * 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 * @return \Illuminate\Http\Response
*/ */
public function destroy(Faq $faq, DeleteFaqsRequest $request) public function destroy(Faq $faq, DeleteFaqsRequest $request)
{ {
$this->faqs->delete($faq); $this->faq->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);
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 ...@@ -32,6 +32,6 @@ class Faq extends BaseModel
public function __construct(array $attributes = []) public function __construct(array $attributes = [])
{ {
parent::__construct($attributes); parent::__construct($attributes);
$this->table = config('access.faqs_table'); $this->table = config('module.faqs.table');
} }
} }
...@@ -23,31 +23,27 @@ class FaqsRepository extends BaseRepository ...@@ -23,31 +23,27 @@ class FaqsRepository extends BaseRepository
{ {
return $this->query() return $this->query()
->select([ ->select([
config('access.faqs_table').'.id', config('mdule.faqs.able').'.id',
config('access.faqs_table').'.question', config('odule.faqs.table').'.question',
config('access.faqs_table').'.answer', config('module.faqs.table').'.answer',
config('access.faqs_table').'.status', config('module.faqs.table').'.status',
config('access.faqs_table').'.created_at', config('module.faqs.table').'.created_at',
]); ]);
} }
/** /**
* @param array $input * @param array $input
* *
* @throws GeneralException * @throws \App\Exceptions\GeneralException
* *
* @return bool * @return bool
*/ */
public function create(array $input) public function create(array $input)
{ {
$faq = self::MODEL; $input['status'] = isset($input['status']) ? 1 : 0;
$faq = new $faq();
$faq->question = $input['question'];
$faq->answer = $input['answer'];
$faq->status = isset($input['status']) ? $input['status'] : 0;
//If faq saved successfully, then return true //If faq saved successfully, then return true
if ($faq->save()) { if (Faq::create($input)) {
return true; return true;
} }
...@@ -55,21 +51,19 @@ class FaqsRepository extends BaseRepository ...@@ -55,21 +51,19 @@ class FaqsRepository extends BaseRepository
} }
/** /**
* @param Model $permission * @param \App\Models\Faqs\Faq $faq
* @param $input * @param array $input
* *
* @throws GeneralException * @throws \App\Exceptions\GeneralException
* *
* return bool * return bool
*/ */
public function update(Model $faq, array $input) public function update(Faq $faq, array $input)
{ {
$faq->question = $input['question']; $input['status'] = isset($input['status']) ? 1 : 0;
$faq->answer = $input['answer'];
$faq->status = isset($input['status']) ? $input['status'] : 0;
//If faq updated successfully //If faq updated successfully
if ($faq->save()) { if ($faq->update($input)) {
return true; return true;
} }
...@@ -77,13 +71,13 @@ class FaqsRepository extends BaseRepository ...@@ -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 * @return bool
*/ */
public function delete(Model $faq) public function delete(Faq $faq)
{ {
if ($faq->delete()) { if ($faq->delete()) {
return true; return true;
...@@ -93,14 +87,14 @@ class FaqsRepository extends BaseRepository ...@@ -93,14 +87,14 @@ class FaqsRepository extends BaseRepository
} }
/** /**
* @param Model $faq * @param \App\Models\Faqs\Faq $faq
* @param $status * @param string $status
* *
* @throws GeneralException * @throws \App\Exceptions\GeneralException
* *
* @return bool * @return bool
*/ */
public function mark(Model $faq, $status) public function mark(Faq $faq, $status)
{ {
$faq->status = $status; $faq->status = $status;
......
...@@ -17,5 +17,8 @@ return [ ...@@ -17,5 +17,8 @@ return [
], ],
'blogs' => [ 'blogs' => [
'table' => 'blogs' 'table' => 'blogs'
],
'faqs' => [
'table' => 'faqs'
] ]
]; ];
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
@endsection @endsection
@section('content') @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 box-success">
<div class="box-header with-border"> <div class="box-header with-border">
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
<div class="col-lg-10"> <div class="col-lg-10">
<div class="control-group"> <div class="control-group">
<label class="control control--checkbox"> <label class="control control--checkbox">
@if(isset($item->status)) @if(isset($faq->status))
{{ Form::checkbox('status', 1, $item->status == 1 ? true :false) }} {{ Form::checkbox('status', 1, $faq->status == 1 ? true :false) }}
@else @else
{{ Form::checkbox('status', 1, true) }} {{ Form::checkbox('status', 1, true) }}
@endif @endif
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
<a class="reset-data" href="javascript:void(0)"><i class="fa fa-times"></i></a> <a class="reset-data" href="javascript:void(0)"><i class="fa fa-times"></i></a>
</th> </th>
<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></th> --}}
<th></th> <th></th>
...@@ -78,10 +78,10 @@ ...@@ -78,10 +78,10 @@
type: 'post' type: 'post'
}, },
columns: [ columns: [
{data: 'question', name: '{{config('access.faqs_table')}}.question'}, {data: 'question', name: '{{config('module.faqs.table')}}.question'},
{data: 'answer', name: '{{config('access.faqs_table')}}.answer'}, {data: 'answer', name: '{{config('module.faqs.table')}}.answer'},
{data: 'status', name: '{{config('access.faqs_table')}}.status'}, {data: 'status', name: '{{config('module.faqs.table')}}.status'},
{data: 'updated_at', name: '{{config('access.faqs_table')}}.updated_at'}, {data: 'updated_at', name: '{{config('module.faqs.table')}}.updated_at'},
{data: 'actions', name: 'actions', searchable: false, sortable: false} {data: 'actions', name: 'actions', searchable: false, sortable: false}
], ],
order: [[1, "asc"]], order: [[1, "asc"]],
......
...@@ -10,5 +10,5 @@ Route::group(['namespace' => 'Faqs'], function () { ...@@ -10,5 +10,5 @@ Route::group(['namespace' => 'Faqs'], function () {
Route::post('faqs/get', 'FaqsTableController')->name('faqs.get'); Route::post('faqs/get', 'FaqsTableController')->name('faqs.get');
// Status // 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