0
1104

What Ziggy?

Myo Thant Kyaw

Ziggy က laravel vue အသုံးပြုသူများအတွက်အဆင်ပြေမဲ့ route helper package တစ်ခုပါ

အဓိကကတော့ laravel vue project အတွင်းမှာ 

vue component ကနေ laravel routes name တွေကိုခေါ်သုံးနိုင်ဖို့ဖြစ်ပါတယ်။

အခုလုပ်နေတဲ့ laravel inertia(vue) မှာလည်း ziggy ကိုသုံးထားပါတယ်။


Eg (pseudo)

laravel web.php

Route::get(‘/detail/{id}’)→name(‘detail’)

Hello.vue


<template>

<a :href="route('detail',1)">Go Detaila>

templae>


အပေါ်က  code ကိုကြည့်ရင် ziggy ရဲ့ အသုံးဝင်ပုံကိုမြင်မယ်ထင်ပါတယ်။

Installation (https://github.com/tighten/ziggy)


  1. =>composer require tightenco/ziggy
  2. => yarn add ziggy-js
  3. => php artisan ziggy:generate
  4. => view/js/app.js(main vue config)  မှာ ပြင်စရာတချို့ရှိပါတယ်


<script>
Vue.mixin({methods:{route:window.route}})
script>



route ကို  vue က global သိအောင် inject လုပ်ပေးထားတာဖြစ်ပါတယ်။

https://vuejs.org/v2/guide/mixins.html

=> view/app.blade.php(mail layout blade file)

 


ရဲ့ အပေါ်မှာ @routes (blade directive) ကိုကြေညာပေးပါ။


ဒါဆိုရင်တော့ Vue component အတွင်းကနေ route တွေကိုခေါ်လို့ရပါပီ။


<a :href=“route(‘detail’,1)”>Go Detaila>

ဒိတိုင်းပေါ့

Comment:
Please Login To Create Comment Login
Loading...