• 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

Archives for March 2019

Laravel + VueJS: Cant call routers within Store.js

March 28, 2019 by ghazalitajuddin Leave a Comment

As mention in Vue Router documentation, we can simply use this.$router.push(‘router-name’) to get to the other component.

For some reason, i have some issues to use it in my store.js.

One of the solution i found here, where i need to exports all declaration inside app.js to other instance, then import it in my store.js.

app.js

const app = new Vue({
    el: '#app',
    router,
    store
});

export {app}

store.js

// import the app instance
import {app} from './app'
.
.
.
//calling example
app.$router.push('route-name');

Reference:

  • https://stackoverflow.com/questions/40736799/how-to-navigate-using-vue-router-from-vuex-actions/53309412#53309412
  • https://stackoverflow.com/questions/40767874/how-to-use-vue-router-from-vuex-state/40768840#40768840

 

Filed Under: Technology Tagged With: action, routes, vuejs, vuex

Laravel + VueJS: Handling Exception In Vuex

March 26, 2019 by ghazalitajuddin Leave a Comment

Example 1

a) Controller 

When using get() method, you can provide constraint that will return collection in array. 

If no object. This will return empty array []

public function search($search)
    {
        
        $group = Group::query($search)
        ->where('name', '=', $search) 
        ->get();

        return response()->json($group, 200);
}

b) Thus, in Store.js (Vuex). We can do like this.

actions : {
        
        checkGroupName : async (context, name) => {

                let { data } = await Axios.get('http://localhost:8888/test/public/api/groups/search/'+name);

                if(data.length === 0){
                
                    context.commit('setGroup',{id:0,name:""}); //set to data to null
                    context.commit('setGroupAvailable',false); //set group availability to false

                }else{

                    context.commit('setGroup',data[0]);
                    context.commit('setGroupAvailable',true);

                }
}
}

Example 2

a) Controller

If you are using first() or firstOfFail() it will retrieve the first results of the query. If not, it will throw an exception (Illuminate\Database\Eloquent\ModelNotFoundException)

public function search($search)
    {
        
        $group = Group::query($search)
        ->where('name', '=', $search) 
        ->first();

        return $group;

    }

b) Store.js

By using try .. catch you can captured any exception occurs during API request.

actions : {
        
        checkGroupName : async (context, name) => {
                
                try{
                
                let { data } = await Axios.get('http://localhost:8888/test/public/api/groups/search/'+name);

                console.log(data)
                
                context.commit('setGroup',data);
                context.commit('setGroupAvailable',true);

            } catch (err){
                
                context.commit('setGroup',{id:0,name:""}); //set to data to null
                context.commit('setGroupAvailable',false); //set group availability to false

            }
}
}

 

 

 

Filed Under: Technology Tagged With: laravel, try catch, vuejs, vuetify, vuex

Laravel + VueJS + Vuetify: Installation

March 8, 2019 by ghazalitajuddin Leave a Comment

Laravel secara default telah pun didatangkan dengan Vuejs. Anda boleh lihat dalam file package.json.

Jadi untuk mula menggunakannya. Pertama sekali sila pastikan anda telah install npm yang membantu anda compile semua asset bagi menguruskan semua js dependencies.

Berikut command install NPM.

npm install

Run command berikut untuk install Vuetify

npm install vuetify --save

package.json akan dikemaskini seperti berikut

Selepas install vuetify. Compile semua asset melalui command npm berikut. 

npm run watch

atau

npm run watch-poll

Command npm run watch ini akan sentiasa update sebarang perubahan yang dibuat pada code kita.

Remember, you should run the npm run dev command each time you change a Vue component. Or, you may run the npm run watch command to monitor and automatically recompile your components each time they are modified.

Buka resources/js/app.js update

import Vue from 'vue'
import Vuetify from 'vuetify'

Vue.use(Vuetify)

Buka resources/sass/app.css update

@import 'https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons';

@import '~vuetify/dist/vuetify.min.css';

Edit main(cth home.blade.php) blade. Tambah pada header seperti berikut

<link rel="stylesheet" href="{{ asset('css/app.css') }}">

Tambah pada sebelum close tag body.

<script src="{{ asset('js/app.js') }}"></script>

 

 

Rujukan

  • https://vuetifyjs.com/en/getting-started/quick-start
  • https://laravel.com/docs/5.7/frontend

Filed Under: Technology

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

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

Kopi Acah-acah Diet

Variasi Coconut Shake Hogoh De Coco

Day Trip Kuantan – Kuala Gandah – Temerloh – Kuantan

Kuih Keria Viral 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. •