Current latest version is 5.2.
Current latest LTS version is 5.1.
To install LTS version 5.1 using create-project command
[php]
composer create-project laravel/laravel blog "5.1.*"
[/php]
Another Kuantan Blogger
Current latest version is 5.2.
Current latest LTS version is 5.1.
To install LTS version 5.1 using create-project command
[php]
composer create-project laravel/laravel blog "5.1.*"
[/php]
Untuk create model dalam Laravel run command berikut
php artisan make:model Ticket
Note: a model name should be singular(Ticket), and a table name should be plural(tickets).
Selepas command berkenaan dilaksanakan, anda akan jumpa file model Ticket.php dalam direktori app/.
Untuk create table dalam Laravel. Kita akan menggunakan Migration.
Migration adalah satu features dalam Laravel yang memudahkan developer track database scheme.
Laravel menggunakan migration untuk apa perubahan yang telah kita lakukan pada database kita.
Kelebihannya, anda dengan mudah boleh buat kemaskini atau revert balik perubahan dengan sekadar command ringkas.
Cth:
php artisan migrate:reset
Create file migration dengan nama create_tickets_table (atau nama lain pun boleh).
php artisan make:migration create_tickets_table
File migration akan dhasilkan dan ditempatkan dalam direktori database/migrations.
File migration akan mempunyai timestamp diawal nama file seperti berikut
2015_06_15_150120_create_tickets_table.php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTicketsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
Bila anda buka file berkenaan ada 2 method penting:
Dengan menambah ‘–create’ diakhir command create migration, Laravel secara otomatis akan generate code tickect table untuk anda.
Cuba delete file migration create ticket table yang terdahulu
2015_06_15_150120_create_tickets_table.php
Kemudian cuba run command berikut
php artisan make:migration create_tickets_table --create=tickets
public function up()
{
Schema::create('tickets', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
});
}
Jika anda lihat method Up mempunyai
$table->increments(‘id’);
merupakan id column dan merupakan primary key pada table berkenaan
$table->timestamps();
merupakan method special dalam Laravel yang menghasilkan kolum created_at dan update_at. Laravel menggunakan kolum ini untuk mengetahui perubahan table berkenaan.
refer disini untuk maklumat penuh migration http://laravel.com/docs/master/migrations
Ubahsuai generated code berkenaan
public function up()
{
Schema::create('tickets', function (Blueprint $table) {
$table->increments('id');
$table->string('title', 255);
$table->text('content');
$table->string('slug')->nullable();
$table->tinyInteger('status')->default(1);
$table->integer('user_id');
$table->timestamps();
});
}
Selepas berpuas hati run command berkenaan untuk create table dan kolum
php artisan migrate
Sepatutnya sekarang table database telah dicipta. Boleh semah pada phpmyadmin.
Jika ada error semasa migrate, sila semak user permission dan juga config file database dan file .ENV.
Artisan adalah Laraavel’s CLI (Command Line Interface). Kita akan banyak menggunakan Atisan untuk membangunkan applikasi Laravel. Artisan boleh digunakan untuk create tables, masukkan data dan lain2.
Cth sebelum ini:
php artisan make:controller PagesController
Untuk melihat senarai command Artisan
php artisan list
Untuk rujukan
Kepada pengguna XAMPP
Just masuk command prompt
Go to laravel directory
Execute command
php artisan --version
[php]
‘components’=>array(
…
‘mail’ => array(
‘class’ => ‘YiiMail’,
‘transportType’ => ‘php’,
‘transportType’ => ‘smtp’,
‘transportOptions’=>array(
‘host’=>’ghazalitajuddin.com’,
//’encryption’=>’tls’,
‘username’=>’***@ghazalitajuddin.com’,
‘password’=>’******’,
‘port’=>25,
),
‘logging’ => true,
‘dryRun’ => false
),
…
),
[/php]
[php]</pre>
$message = new YiiMailMessage;
$message->setBody($model->message);
$message->subject = $model->subject;
$message->addTo($model->to);
$message->from = Yii::app()->params[‘adminEmail’];
Yii::app()->mail->send($message);
<pre>[/php]
[php]
class EmailForm extends CFormModel
{
public $email;
public $to;
public $subject;
public $message;
public $from;
/**
* Declares the validation rules.
*/
public function rules()
{
return array(
// name, email, subject and body are required
array(’email, to, subject, message’, ‘required’),
// email has to be a valid email address
array(’email’, ’email’),
// verifyCode needs to be entered correctly
//array(‘verifyCode’, ‘captcha’, ‘allowEmpty’=>!CCaptcha::checkRequirements()),
);
}
/**
* Declares customized attribute labels.
* If not declared here, an attribute would have a label that is
* the same as its name with the first letter in upper case.
*/
public function attributeLabels()
{
return array(
‘verifyCode’=>’Verification Code’,
);
}
}
[/php]
[php]
<?php
$this->pageTitle=Yii::app()->name . ‘ – Email Others’;
$this->breadcrumbs=array(
‘Email’,
);
?>
<h1>Email others</h1>
<?php if(Yii::app()->user->hasFlash(’email’)): ?>
<div class="flash-success">
<?php echo Yii::app()->user->getFlash(’email’); ?>
</div>
<?php else: ?>
<p>
If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
</p>
<div class="form">
<?php $form=$this->beginWidget(‘CActiveForm’, array(
‘id’=>’email-form’,
‘enableClientValidation’=>true,
‘clientOptions’=>array(
‘validateOnSubmit’=>true,
),
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,’email’); ?>
<?php echo $form->textField($model,’email’); ?>
<?php echo $form->error($model,’email’); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,’to’); ?>
<?php echo $form->textField($model,’to’); ?>
<?php echo $form->error($model,’to’); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,’subject’); ?>
<?php echo $form->textField($model,’subject’,array(‘size’=>60,’maxlength’=>128)); ?>
<?php echo $form->error($model,’subject’); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,’message’); ?>
<?php echo $form->textArea($model,’message’,array(‘rows’=>6, ‘cols’=>50)); ?>
<?php echo $form->error($model,’message’); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,’from’); ?>
<?php echo $form->textArea($model,’from’); ?>
<?php echo $form->error($model,’from’); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton(‘Submit’); ?>
</div>
<?php $this->endWidget(); ?>
</div><!– form –>
<?php endif; ?>
[/php]