• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

GhazaliTajuddin.com

Another Kuantan Blogger

  • Home
  • Blog
    • Kuantan
    • Foods
    • Technology
    • Health
  • Stock Photography
    • Senarai Microstock Agency
    • Membuka akaun contributor Shutterstock.com
    • Tips untuk 10 keping gambar pertama Shutterstock.com
    • Mengapa Shutterstock.com reject gambar / submission
    • Model Release
    • Bagaimana withdraw earning daripada Fotolia
    • Bagaimana untuk mengisi keyword kepada imej dengan menggunakan Adobe Photoshop

migration

Migrate:Refresh does not work after deleting / renaming migration

March 7, 2019 by ghazalitajuddin Leave a Comment

If you just like me, accidently renaming the migration and then later realise something goes wrong or having some kind of migration error that really makes you want to jump out shouting hardly, this is might be a solution for you.

First just reset your migration.

php artisan migrate: reset

Then browse to your migration tables, suppose to be empty. BUT there will a record left that you can manually delete it.

Then try to migrate again. Hope it will settle your problem. Good luck!

Reference: https://github.com/laravel/framework/issues/2105

 

 

Filed Under: Technology Tagged With: laravel, migration, reset, Seeder

Laravel migration untuk tukar table column field type

November 4, 2016 by ghazalitajuddin Leave a Comment

Run command berikut

php artisan make:migration tukar_field_type_table_parcel

Edit file migration TukarFieldTypeTableParcel.php seperti berikut

Function Up()

public function up()
{
//
Schema::table('parcels', function(Blueprint $table)
{

$table->integer('courier')->unsigned()->change();
$table->foreign('courier')->references('id')->on('couriers');

$table->integer('distributor')->unsigned()->change();
$table->foreign('distributor')->references('id')->on('distributors');
});
}

Function Down()

public function down()
{
//

Schema::table('parcels', function(Blueprint $table)
{

$table->dropForeign('parcels_courier_foreign');
$table->dropForeign('parcels_distributor_foreign');

});

}

*Unsigned() – Bertujuan memastikan nilai integer berkenaan bukan negative

*Sila pastikan type untuk setiap foreginer field dan reference field adalah sama.

 

 

Filed Under: Technology Tagged With: change type, laravel, migration, tukar type

Laravel Migration Rename Table

October 27, 2016 by ghazalitajuddin Leave a Comment

Biasa ler buat silap. Mana ada orang tak buat silap? 😛

Setiap kali buat perubahan pada table run command berikut

php artisan make:migration rename_nama_table_silap

Edit file migration dalam database/migrations/

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class RenameCourierTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::rename('courier', 'couriers');
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
Schema::rename('couriers', 'courier');
}
}

 

 

Filed Under: Technology Tagged With: laravel, laravel rename table, migration, rename table

Laravel: Create Table

March 29, 2016 by ghazalitajuddin Leave a Comment

MIGRATION

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 NEW MIGRATION FILE

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:

  • Method Up: Utk add table, column kepada database
  • Method Down: Untuk reverse apa up buat

CREATE MIGRATION dengan opsyen ‘–CREATE’

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

CREATE TABLE SEBENAR

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.

Filed Under: General Tagged With: artisan, Framework, laravel, migration, MVC, PHP, table

Primary Sidebar

“Solat. Sabar. Syukur. Senyum. Sedekah.”

For Collaboration, Events & Review, kindly contact me at +6016[-]9212092 or click Whatsapp button on this page.

Sponsor

Recent Posts

BadMethodCallException Method Illuminate\Database\Eloquent\Collection::roles does not exist.

User Roles And Permissions Without Package Laravel 10

Laravel Many To Many Relationship

Makan malam bersama keluarga di Awangan Palace

Sarapan pagi di Warung Gulai Kawah

Recent Comments

  • helmi on Personal Tips Berhenti Merokok
  • ghazalitajuddin on Personal Tips Berhenti Merokok
  • helmi on Personal Tips Berhenti Merokok
  • ghazalitajuddin on Nasi Lemak Kukus Restoran Zaman. Otai masih berbisa.
  • ghazalitajuddin on Air tangki radiator Proton Exora cepat kering? Cuba tukar penutup radiator!
  • Mal on Nasi Lemak Kukus Restoran Zaman. Otai masih berbisa.
  • Firdaus on Air tangki radiator Proton Exora cepat kering? Cuba tukar penutup radiator!

My Link

  • Takaful Insurance Web

JJCM

Singgah beli keropok di Keropok Warisan Losong Kuala Terengganu

Rojak Pak Lah Taman Gelora

Nasi Lemak Kukus Restoran Zaman. Otai masih berbisa.

7 Lokasi Nasi Dagang Terbaik di Kuantan

Sarapan pagi di Arked Sri Gambut

Tags

bebas rokok berhenti merokok breakfast Controller Framework Gezzeg Photography & Design health jalan-jalan cari makan jalan-jalan cari makan kuantan jjcm jjcm kuantan Jurufoto Kuantan Kuantan Kuantan Photographer kuantan programmer kuantan web developer kuantan webmaster laravel merokok merbahayakan kesihatan model MVC nikmat rokok OOP Pahang Pahangtourism pahang tourism Photo Manipulation PHP rajalanun retired smoking revisit pahang 2018 shutterstock stop smoking stop smoking tips stop smoking withdrawal symptom tips tips berhenti merokok View visit malaysia 2020 visit pahang visitpahang white wordpress yii Yii Framework

Recent Posts

  • BadMethodCallException Method Illuminate\Database\Eloquent\Collection::roles does not exist.
  • User Roles And Permissions Without Package Laravel 10
  • Laravel Many To Many Relationship
  • Makan malam bersama keluarga di Awangan Palace
  • Sarapan pagi di Warung Gulai Kawah

Copyright © 2025 — Ghazali Tajuddin • All rights reserved. •