• 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

laravel

Laravel: Exception Handling For NotFoundHttpException

October 10, 2017 by ghazalitajuddin 2 Comments

Ramai salah satu komponen penting dalam MVC adalah Routing. Capaian setiap maklumat dikawal melalui route yang telah didefinasikan. 

Cthnya:

  • http://www.ghazali.tajuddin/
  • http://www.ghazali.tajuddin/membership
  • http://www.ghazali.tajuddin/membership/1/edit

Tetapi bagaimana sekiranya terdapat capaian secara tidak sengaja kepada route yang tidak didefinasikan? Error lah jawapannya, atau lebih tepat NotFoundHttpException Exception.

Sudah pastinya tak manis bila bila tetamu sampai ke ruangan yang salah, sebaiknya adalah kita menyediakan satu page 404 bagi menangani masalah ini.

Nasib baik Laravel ada cara mudah.

Create satu folder errors/ dalam direktori resources/views/errors/.

Create satu file 404.blade.php. Customize ikut citarasa anda.

Setel sudah. Bole test apa2 route, akan bawa ke page 404.

Selamat mencuba ya!

Refer: https://github.com/laravel/framework/blob/5.0/src/Illuminate/Foundation/Exceptions/Handler.php#L114-L126

protected function renderHttpException(HttpException $e)
	{
		$status = $e->getStatusCode();
		if (view()->exists("errors.{$status}"))
		{
			return response()->view("errors.{$status}", [], $status);
		}
		else
		{
			return (new SymfonyDisplayer(config('app.debug')))->createResponse($e);
		}
	}

 

Filed Under: Technology Tagged With: exception, laravel, NotFoundHttpException, throws exceptions

Learning Laravel 5 Building Practical Applications

September 3, 2017 by ghazalitajuddin Leave a Comment

Sedar tak sedar ada banyak juga buku aku beli online. Mostly buku programming ler. Mostly format PDF. Pernah juga beli hardcopy, tapi lebih practical dalam softcopy. Senang nak share dan copy source code. Selepas bayar terus bleh download, kalau hardcopy mungkin ambil masa untuk courier ke Malaysia pulak.

So hari ni aku nak review sebuah buku Laravel oleh Nathan Wu. 

Tajuk : Learning Laravel 5 Building Practical Applications
Pengarang : Nathan Wu
Url :  https://learninglaravel.net/laravelbook
Bahasa  : English
Harga : USD49 USD35
Pakej :
  • Lifetime access to the online book. (Read 70% of the book for FREE!)
  • Digital books: PDF, MOBI, EPUB (Premium Only)
  • Full source code (Premium Only)
  • Access new chapters of the book while it’s being written (Premium Only)
  • A community of 10000+ students learning together.
  • Amazing bundles and freebies to help you become a successful developer.
  • iPhone, iPad and Android Accessibility.

Buku ni aku beli semasa 1st Edition(Laravel 5.2) lagi, ketika post ini ditulis buku ni dah keluar 3rd Edition(Laravel 5.4). Korang akan membangunkan dua applikasi, Support Ticket System dan Blog Application. Pembangunan dua applikasi ini cukup untuk membawa pembaca mengenali, memahami, dan menggunakan Framework Laravel dari ground up. Installasi server, installasi laravel framework, installasi vendor, konfigurasi model, controller, view, eloquent, relationship etc. 

Cara Penulisan

Secara umumnya, buku ini amat sesuai dibaca dan dijadikan rujukan oleh pengguna baru dan lama. NW memberi penerangan yang jelas dan menggunakan pendekatan praktikal dari awal sehinggalah akhir bab, dari installasi sehinggalah kepada deploy. Penerangannya disokong oleh kod-kod yang boleh digunakan dan sentiasa dikemaskini dari masa ke semasa. Jadi, kepada yang suka kaedah baca dan praktik dalam mempelajari sesuatu memang sesuai dapatkan buku ini.

Pengisian

Chapter 1 – Installing Laravel

Chapter 2 – Building Our First Website

Chapter 3 – Building A Support Ticket System

Chapter 4 – Building A Blog Application

Chapter 5 – Deploying Our Laravel Applications

 

Kesimpulan

Secara peribadi antara buku terbaik laravel. Kalau korang memang berniat nak beli, silakan. Dengan harga USD49 USD35, amat berbaloi. Sebab setiap kali ada versi terkini, korang pun akan dapat download versi terkini berkenaan, dalam masa sama yang lama still pun boleh download. Tiada yang lebih berbaloi! 

Bintang

Aku bagi 4/5 bintang ajela. Mana ada perfect! 

Sekian!

Filed Under: Technology Tagged With: book, ebook, laravel, Learning Laravel 5 Building Practical Applications, pdf

Laravel: Upgrade Laravel 5.4 to 5.5

August 28, 2017 by ghazalitajuddin Leave a Comment

Update Composer.json

tukar dependencies framework 5.4 kepada 5.5 

"require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.5.*", //<-- tukar drpd 5.4.*
        "laravel/tinker": "~1.0"
    },

tukar php unit 5.6 kepada 5.7

"require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.7"//<-- tukar daripada 5.6
    },

run composer update

composer update

Boleh refer

https://laravel.com/docs/5.5/upgrade

https://laracasts.com/discuss/channels/laravel/upgrading-to-55-from-51

 

Filed Under: Technology Tagged With: laravel, lts, upgrade

Laravel Special Method

January 18, 2017 by ghazalitajuddin Leave a Comment

There is a lot special functions that helps simplified our code like this

  1. find($id) takes an id and returns a single model. If no matching model exist, it returns null.
  2. findOrFail($id) takes an id and returns a single model. If no matching model exist, it throws an error.
  3. first() returns the first record found in the database. If no matching model exist, it returns null.
  4. firstOrFail() returns the first record found in the database. If no matching model exist, it throws an error.
  5. get() returns a collection of models matching the query.
  6. lists($column) returns a collection of just the values in the given column.
  7. toArray() converts the model/collection into a simple PHP array.

Looking for more? Visit here or https://laravel.com/docs/5.3/eloquent-collections.

Filed Under: Technology Tagged With: 5.3, collections, functions, helpers, laravel, methods, pre, special

Laravel Middleware

January 17, 2017 by ghazalitajuddin Leave a Comment

Middleware is a class that have special function in Laravel.

Middleware placed in between the User and  Apps. 

Before you can access the Apps, Middleware will do his job first.

We can use Middleware to do several thing

  • Do you authenticated?
  • What is your role?
  • Do you authorized?
  • Can you perform this action?
  • etc
class MemberMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        //1. User must be authenticated
        //2. User must should be a "member"
        

        if(Sentinel::check() && Sentinel::getUser()->roles()->first()->slug == 'member')

            return $next($request);

        else

            return redirect('/login')->withErrors('Please login to access this area.');
        

        
    }
}

Another example

class ProfileMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        1. Get Profile Id
        2. Get Profile User Id
        3. User must own the Profile

        //$ProfileId = $request->segments()[1]; //boleh pakai
        //$profileId= Profile::find($this->route()->parameter('profileShow'));
        
        $ProfileId = $request->route()->parameter('id'); //boleh pakai
        $profile = Profile::findOrFail($ProfileId);

        if ($profile->user_id !== Sentinel::getUser()->id) {
            
           // dd($request->user()->id);
           // abort(403, 'Unauthorized action.');
              // return redirect('/profile')->withError('Permission Denied');
            return redirect()->back()->withErrors('Permission Denied!');
            }

        return $next($request);
        
    }
}

Another finest!

class ProfileMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        //get User Id
        $UserId=$request->id;

        //get User Profile
        $profile=Profile::whereUserId($UserId)->first();

        if ($profile->user_id !== Sentinel::getUser()->id) {         
            return redirect()->back()->withErrors('Permission Denied!');
            }

        return $next($request);
        
    }
}

 

Filed Under: Technology Tagged With: Authentication, Authorization, laravel, middleware, sentinel

Laravel Handling Exceptions

January 17, 2017 by ghazalitajuddin Leave a Comment

This is examples how Laravels handle exceptions.

try{
..
.. Business Logic ..
..
}
catch(ThrottlingException $e){
$delay = $e->getDelay();
return redirect()->response->withErrors("You are banned for $delay seconds.");
}
catch(NotActivatedException $e){
return redirect()->response->withErrors("You account is not activated.");
}

Not to forget at the top of the class

use Cartalyst\Sentinel\Checkpoints\ThrottlingException;
use Cartalyst\Sentinel\Checkpoints\NotActivatedException;

Filed Under: General Tagged With: exceptions, laravel, NotActivatedException, sentinel, ThrottlingException

  • « Go to Previous Page
  • Page 1
  • Page 2
  • Page 3
  • Page 4
  • Interim pages omitted …
  • Page 7
  • Go to Next Page »

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

Lunch di Nasi Kukus Alom

Aneka Kuih Tradisional

Cendol Terbaik Di Kuantan

Meraikan hari lahir di Loteng

Daging Bakar Daun Pisang Pekan

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. •