Laravel CRUD And CMS

Built Backend Administrator for real Internet / Intranet web application Easier , Faster , Proffessional

Patch version LCRUD 2.0

Bellow is list minor issue on version 2.0 .

If you want to fix it , follow this intruction :

1. Set default group for new user registrant ( March , 29 2014 )
  file location :
 protected/app/controllers/UserController.php
 change line 37:
$authen->active = '0';
/* set new users as group 3 */
$authen->group_id = '3';
/* end add code */
$authen->save();


2. JS issue on Chrome ( March , 30 2014 )
File location :
sximo/js/sximo.js
replace with new js file
sximo.js

2. Menu issue ( April, 01 2014 )
File location :
protected/app/controllers/MenuController.php
replace with new file
MenuController.php
File location :
protected/app/library/SiteHelpers.php
replace with new file
SiteHelpers.php

ALL patch will be integrated on next release updates

Thank you !

Master Detail ( Laravel CRUD V2 )

In laravel CRUD and CMS v2 , master detail is feature for filtering rows detail by spesific field , ID from master table.
Example you have rows master detail :



The picture showing you where invoce table related to invoiceline table with 'InvoiceId' key relation.
We used call it "One to Many " relation, where every row on table invoice will have one or more rows detail in invoiceline table .

Ok let's turn the logic into real application .

Step 1

- Create 2 modules , Invoice and Invoiceline ( please see previous tutorial creating module )
http://mangsoft.blogspot.com/2014/03/create-simple-crud-laravel-41-using.html

Step 2 .

Create new menu for Invoice module

Step 3

Edit module Invoice and go to master detail tab :


Fill in form field as illustrated image above . then save master detail

Now go to Invoice module , you will see new menu at dropdown button at every rows.

Test it by clicking link 'View orders detail' .
it will bring you to invoiceline module , with header information about master row details.


 It's Easy right ? so why you dont try it by your self .

View Demo Page  

Good Luck !!




Formating rows on grid table

Now let's continue our tutorial , in this section we will guide you  to format rows grid at module generated by LCRUD v2.

After created module , app creating folowing files  :
  • protected
    • app
      • controllers
        • YourmoduleController.php
      • models
        • Yourmodule.php
      • views
        • yourmodule
          • index.blade.php
          • form.blade.php
          • view.blade.php

 Now open index.blade.php with your favorite php editor
at line 89 - 100 , you should find code html as shown bellow :

 @foreach ($tableGrid as $field)
  @if($field['view'] =='1')
  <td>      
  @if($field['attribute']['image']['active'] =='1')
   <img src="{{ asset($field['attribute']['image']['path'].'/'.$row->$field['field'])}}" width="50" />
  @else 
   {{ $row->$field['field'] }} 
  @endif       
  </td>
  @endif
     
 @endforeach
 oke , lets understanding what's code does
example
you have table with following items :

Id (int) , name ( varchar ) , email ( varchar ) , status ( enum '1','0' )

now let format emails as link mailto and status ( if 1 show Active and 0 inactive )


 @foreach ($tableGrid as $field)
  @if($field['view'] =='1')
  <td>      
  @if($field['attribute']['image']['active'] =='1')
   <img src="{{ asset($field['attribute']['image']['path'].'/'.$row->$field['field'])}}" width="50" />
   
  @elseif($field['field'] == 'email')
   <!-- formating email as link -->
   <a href="mailto:{{ $row->email }}"> {{ $row->email }}  </a>
  @elseif($field['field'] == 'status')
   <!-- Formating status , set active or inactive -->
   {{  ($row->status == 1 ? 'Active' : 'Inactive') }} 
  @else 
   {{ $row->$field['field'] }} 
  @endif       
  </td>
  @endif
     
 @endforeach

Working with MySQL Statement

This is heart of your module , from this query module are built up . remember if you want to display/show any field from table database , you need to include field on your query
Query are splited to 3 part , SQL select , SQL Where , SQL Group

Ilustration you have table customers with following field :

CREATE TABLE `customer` (
  `CustomerId` int(11) NOT NULL AUTO_INCREMENT,
  `FirstName` varchar(40) CHARACTER SET utf8 NOT NULL,
  `LastName` varchar(20) CHARACTER SET utf8 NOT NULL,
  `Company` varchar(80) CHARACTER SET utf8 DEFAULT NULL,
  `Address` varchar(70) CHARACTER SET utf8 DEFAULT NULL,
  `City` varchar(40) CHARACTER SET utf8 DEFAULT NULL,
  `State` varchar(40) CHARACTER SET utf8 DEFAULT NULL,
  `Country` varchar(40) CHARACTER SET utf8 DEFAULT NULL,
  `PostalCode` varchar(10) CHARACTER SET utf8 DEFAULT NULL,
  `Phone` varchar(24) CHARACTER SET utf8 DEFAULT NULL,
  `Fax` varchar(24) CHARACTER SET utf8 DEFAULT NULL,
  `Email` varchar(60) CHARACTER SET utf8 NOT NULL,
  `SupportRepId` int(11) DEFAULT NULL,
  PRIMARY KEY (`CustomerId`),
  KEY `IFK_CustomerSupportRepId` (`SupportRepId`)
) ENGINE=MyISAM AUTO_INCREMENT=60 DEFAULT CHARSET=latin1


EmployeeId, FirstName , LastName , Title, ReportsTo, BirthDate ,HireDate, Address ,City , State , Country , PostalCode , Phone , Fax , Email. 

At the firs time creating module using 'employee' table , generator will create single query line :
SQL Select :
SELECT employee,* FROM employee
SQL Where :
 WHERE employee.EmployeeId IS NOT NULL
SQL Group :

Why LCRUD Creating automatic " WHERE employee.EmployeeId IS NOT NULL " ? this is for prevent when users submit search form
 The result will look like :

Join Query

Now lets trying making simple join query , as you can see "ReportsTo" field is displaying number reference to EmployeeId
We plan to change  "ReportsTo" to employee name  .
 
SELECT employee.*, b.FirstName AS ReportName FROM employee 
LEFT JOIN employee AS b ON employee.EmployeeId = b.ReportsTo
Save this new query statment . next go to table tab hide ReportsTo field and display ReportName

Contact Form in Laravel ( LCRUD V2 )

In this tutorial , we will trying to make contact form using default page CMS from LCRUD v2. and send message to email

Step 1 : Create new page

Next Go to : Tools -> PageCMS -> Create New
Copy following line code to your editor

<div class="page-content">

    <div class="page-header">
      <div class="page-title">
        <h3> Contact Us <small> Send any message to us </small></h3>
      </div>
    </div>

	
    <div class="breadcrumb-line">
      <ul class="breadcrumb">
        <li><a href="{{ URL::to('') }}">Home</a></li>
		<li><a href="{{ URL::to('?p=contactus') }}"> Contact Us </a></li>
        <li class="active"> Add </li>
      </ul>
	</div>  
	

{{ Form::open(array('url'=>'/saveContactForm', 'class'=>'form-vertical','parsley-validate'=>'','novalidate'=>' ')) }}
<div class="col-sm-6 well">
	@if(Session::has('message'))	  
		   {{ Session::get('message') }}
	@endif	
		
		<ul class="parsley-error-list">
			@foreach($errors->all() as $error)
				<li>{{ $error }}</li>
			@endforeach
		</ul>

		 <div class="form-group  ">
		<label for="ipt"> Your Name</label>
		  {{ Form::text('name', null,array('class'=>'form-control', 'placeholder'=>'', 'required'=>'Your Name'  )) }} 
		
	  </div> 			
						 					
	  <div class="form-group  ">
		<label for="ipt"> Your Email</label>
		
		  {{ Form::text('sender', null,array('class'=>'form-control', 'placeholder'=>'', 'required'=>'email'  )) }} 
		
	  </div> 					
	  <div class="form-group  ">
		<label for="ipt"> Subject </label>
		
		  {{ Form::text('subject', null,array('class'=>'form-control', 'placeholder'=>'Subject', 'required'=>'true'   )) }} 
		 
	  </div> 					
	  <div class="form-group  ">
		<label for="ipt"> Message </label>	
		{{ Form::textarea('message',null,array('class'=>'form-control', 'placeholder'=>'Type your message here', 'required'=>'true'   )) }}		 
	  </div>
	  <div class="form-group  ">
		<button type="submit" class="btn btn-primary ">  Send Form </button>		 
	  </div>	  
	  
</div>	   
{{ Form::close() }}

</div>
	  

Step 2 : Add Line code to routes

Next we need to create new routers to send data post from contact form

open your file protected/app/routes.php
copy this code :
Route::post('/saveContactForm',function()
{
	$this->beforeFilter('csrf', array('on'=>'post'));
	$rules = array(
			'name'		=>'required',
			'subject'	=>'required',
			'message'	=>'required|min:20',
			'sender'	=>'required|email'			
	);
	$validator = Validator::make(Input::all(), $rules);	
	if ($validator->passes()) 
	{
		
		$data = array('name'=>Input::get('name'),'sender'=>Input::get('sender'),'subject'=>Input::get('subject'),'notes'=>Input::get('message')); 
		Mail::send('emails.contact', $data, function($message) 
		{
			$message->to(CNF_EMAIL, CNF_APPNAME);
			$message->from(Input::get('sender'), Input::get('name'));
			$message->subject(Input::get('subject'));
		});	
		return Redirect::to('?p=contactus')->with('message', SiteHelpers::alert('success','Thank You , Your message has been sent !'));	
			
	} else {
		return Redirect::to('?p=contactus')->with('message', SiteHelpers::alert('error','The following errors occurred'))
		->withErrors($validator)->withInput();
	}	
});

Step 3 : Create mail template

Crete new file /protected/app/views/emails/contact.blade.php
Copy follwing code into new file

<!DOCTYPE html>
<html lang="en-US">
	<head>
		<meta charset="utf-8">
	</head>
	<body>
		<h2>Hello Admin , </h2>
		<p> You have new contact mail from  </p>
		<p>
			Email : {{ $sender }} <br />
			Name : {{ $name }}<br />
			Password : {{ $subject }}<br />
		</p>
		<p> Message : </p>
		<div>
			{{ $notes }}
		</div>
		
		<p> Thank You </p><br /><br />
		
		{{ CNF_APPNAME }} 
	</body>
</html>

Step 4 : Creating Menu

Now , you need create menu , so users will easy to accesss page contact .

Go To : Tools -> Menu
create new top menu named 'Contact Us ' and linked module to pages Contact
That's it guys , hopely this will help you .
GOOD LUCK !

Create Pages Using LCRUD v.2

Page CMS is new features in Laravel CRUD & Administrator version  2.0.
This feature allow you to create page for frontend ( Public ) or Private.

Before you begin creating pages , you have to know that LCRUD create file everytime you create pages , its mean you have full control to insert everything in content such tag php , css , javasript etc .

Lets start :
Go to Tools > page CMS > click button create

Create Simple CRUD ( Laravel 4.1 ) using LCRUD



Before you create module , you have to create table for module you will created . this app doest have feature to create table database , so you need phpmyadmin or other mysql tools for creating table