VIDEO
Step
- 1) Open Command Prompt
C:\Users\subramanyam>cd..
C:\Users>cd..
C:\>cd xampp
C:\xampp>cd htdocs
C:\xampp\htdocs>cd laravelcms
C:\xampp\htdocs\laravelcms>php artisan asgard:module:scaffold
Please enter the module name in
the following format: vendor/name:
> laravelcms/questionnaire
Do you want to use Eloquent or
Doctrine ? [Eloquent]:
>
Enter entity name. Leaving
option empty will continue script. [<none>]:
> questionnaire
Enter entity name. Leaving
option empty will continue script. [<none>]:
>
Enter value object name. Leaving
option empty will continue script. [<none>]:
>
Module generated and is ready to be used.
C:\xampp\htdocs\laravelcms>
Close
command prompt.
Step
- 2) Display In Admin Menu
Login in admin => Users => Roles => Admin - Actions - Click on
"Edit" icon.
=> Permissions Tab => Goto recently created module(Ex :
questionnaire) - Select All => "Update" ( at botom of page )
Now Questionnaire module is displayed & here we can manage all
"questionnaire".
Step
- 3) Change Module title in Sidebar
Modules=> Questionnaire => Sidebar => SidebarExtender.php in
"extendWith(Menu $menu)" method.
Replace : $group->item(trans('questionnaire::abcs.title.abcs'),
function (Item $item) {
With
: $group->item('Questionnaire', function (Item $item) {
Refresh Admin Page => You can see Module Name is changed
Step
- 4) Removing Database Migration Translation File & Entities
QuestionnaireTranslation.php
Modules=> Questionnaire => Database => Migrations => remove
2015_12_04_055122094610_create_questionnaire_questionnaire_translations_table.php
Modules=> Questionnaire => Entities => remove QuestionnaireTranslation.php
Step
- 5) Migrate Table
Modules=> Questionnaire => Database => Migrations => open
2015_12_04_055121842586_create_questionnaire_questionnaires_table.php
Replace
:
---------------------------
public function up()
{
Schema::create('questionnaire__questionnaires',
function(Blueprint $table) {
$table->engine
= 'InnoDB';
$table->increments('id');
// Your fields
$table->timestamps();
});
}
With :
( add column names)
----------------------------------
public function up()
{
Schema::create('questionnaire__questionnaires',
function(Blueprint $table) {
$table->engine
= 'InnoDB';
$table->increments('id');
// Your fields
$table->string('question');
$table->text('answer');
$table->timestamps();
});
}
Run Migration Command in Command
Prompt
---------------------------------------
C:\xampp\htdocs\laravelcms>php
artisan module:migrate Questionnaire
Migrated:
2015_12_04_055121842586_create_questionnaire_questionnaires_table
Modules => Questionnaire => Entities => Questionnaire.php
Comment "use
Translatable;"
---------------------------
//use Translatable;
Replace: protected
$fillable = [];
With:
( column names) : protected $fillable = ['question','answer'];
Step
- 6) Add Fileds in Default Entity
http://localhost/laravelcms/public/en/backend/questionnaire/questionnaires
Modules=> Questionnaire => Resources => Views => admin
=> questionnaires => Open index.blade.php
Replace: ( both at top( ~ at line 31) and bottom
( ~ at line 56)
-----------------------------------------------------------------
<th>{{ trans('core::core.table.created at') }}</th>
<th data-sortable="false">{{
trans('core::core.table.actions') }}</th>
With ( add your columns here )
-------------------------------
<th>Question</th>
<th>Answer</th>
<th>{{ trans('core::core.table.created at') }}</th>
<th data-sortable="false">{{
trans('core::core.table.actions') }}</th>
and add data columns,
-------------------------
<?php foreach ($questionnaires as $questionnaire): ?>
<tr>
<td>
<a href="{{ route('admin.questionnaire.questionnaire.edit',
[$questionnaire->id]) }}">
{{ $questionnaire->question }}
</a>
</td>
<td>
<a href="{{ route('admin.questionnaire.questionnaire.edit',
[$questionnaire->id]) }}">
{{ $questionnaire->answer }}
</a>
</td>
=> Refresh Page, Columns are added in table.
Step
- 7) Add Columns in create
http://localhost/laravelcms/public/en/backend/questionnaire/questionnaires/create
Modules=> Questionnaire => Resources => views => admin => questionnaires => partials =
> create-fields.blade.php
Replace :
----------------------------
<div class="box-body">
<p>
Your fields //
</p>
</div>
With :
---------------------------
<div class="box-body">
{!!
Form::normalInput('question', 'Question', $errors) !!}
{!!
Form::normalTextarea('answer', 'Answer', $errors) !!}
</div>
Refresh Page -
http://localhost/laravelcms/public/en/backend/questionnaire/questionnaires/create
Two fileds added - question, answer
Step
- 8) Load Data into Table -
http://localhost/laravelcms/public/en/backend/questionnaire/questionnaires
Modules=> Questionnaire => Http => Controllers => QuestionnaireController.php
at ~ Line # 28
Replace:
----------------------
public function index()
{
//$questionnaires =
$this->questionnaire->all();
return
view('questionnaire::admin.questionnaires.index', compact(''));
}
With:
---------------------
public function index()
{
$questionnaires =
$this->questionnaire->all();
return
view('questionnaire::admin.questionnaires.index', compact('questionnaires'));
}
Step
- 9) Add Columns in update
Modules=> Questionnaire => Resources => views => admin => questionnaires => partials =
> edit-fields.blade.php
Replace :
----------------------------
<div class="box-body">
<p>
Your fields //
</p>
</div>
With :
---------------------------
<div class="box-body">
{!!
Form::normalInput('question', 'Question', $errors) !!}
{!!
Form::normalTextarea('answer', 'Answer', $errors) !!}
</div>
Step
- 10) Remove HTML tags in table content -
http://localhost/laravelcms/public/en/backend/questionnaire/questionnaires
Modules=> Questionnaire => Resources => Views => admin
=> questionnaires => Open index.blade.php
Replace:
{{ $questionnaire->answer }}
With: {!!
$questionnaire->answer !!}
Refresh page
Step
- 11) Limit Column content size http://localhost/laravelcms/public/en/backend/questionnaire/questionnaires
Modules=> Questionnaire => Resources => Views => admin
=> questionnaires => Open index.blade.php
Replace:
{{ $questionnaire->answer }}
With:
{!!
str_limit($questionnaire->answer,100) !!}
Step
- 12) Add Validations in create
Create New File - CreateQuestionnaiteRequest.php in Modules=>
Questionnaire => Http => Requests
Enter Following,
---------------------------------
<?php
namespace Modules\Questionnaire\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CreateQuestionnaiteRequest extends FormRequest{
public function
rules(){
return
[
'question'=>'required',
'answer'=>'required'
];
}
public function
authorize(){
return
true;
}
public function
messages(){
return
[];
}
}
Update File - Modules=> Questionnaire => Http => Controllers
=> Admin => QuestionnaireController.php
----------------------------------
Before Class add line,
use Modules\Questionnaire\Http\Requests\CreateQuestionnaiteRequest;
Replace: public function store(Request
$request){
With: public function
store(CreateQuestionnaiteRequest $request){
Open & Check for validation
---------------------------
http://localhost/laravelcms/public/en/backend/questionnaire/questionnaires/create
Step
- 13) Add Validations in update
Create New File - UpdateQuestionnaiteRequest.php in Modules=>
Questionnaire => Http => Requests
Enter Following,
---------------------------------
<?php
namespace Modules\Questionnaire\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdateQuestionnaiteRequest extends FormRequest{
public function
rules(){
return
[
'question'=>'required',
'answer'=>'required'
];
}
public function
authorize(){
return
true;
}
public function
messages(){
return
[];
}
}
Modules=> Questionnaire =>
Http => Controllers => Admin => QuestionnaireController.php
Before Class add line,
use
Modules\Questionnaire\Http\Requests\UpdateQuestionnaiteRequest;
Replace: public function update(Questionnaire
$questionnaire, Request $request)
With: public function update(Questionnaire
$questionnaire, UpdateQuestionnaiteRequest $request)
Step
- 14) Update Labels
Modules=> Questionnaire => Resources => lang=> en => templatecategories.php
Step
- 15) Update Sidebar Menu Items
Modules=> Questionnaire => Sidebar => SidebarExtender.php
That's It :-)