• 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

object

Laravel + VueJS: Calling POST API with Object Input

April 1, 2019 by ghazalitajuddin Leave a Comment

In this example, to insert data to our table, we use axios to make POST request to our API with json object data. Example structure of our object as illustrates

API Test with Insomnia

The data object is passed from our front end form to our store.js. In our store.js, inside our actions

let { data } = await Axios.post('http://localhost:8888/test/public/api/learners', {
                body: learnerdetail
            });

When the object received by the controller, it will pass to the appropriate method which in this case is store method().

public function store(Request $request)
    {
        $learner = new Learner();
        $learner->name = $request->input('body.name');
        $learner->learner_id = $request->input('body.learner_id');
        $learner->section = $request->input('body.section');
        $learner->save();

        //return $learner;
    }

 

 

Filed Under: Technology Tagged With: api, axios, json, laravel, object, POST, vuejs

Kelebihan Laravel Relationship Eloquent

November 5, 2016 by ghazalitajuddin Leave a Comment

Antara sebab aku nak belajar sangat menggunakan framework ni adalah disebabkan oleh ia menyediakan teknik query atau capaian data yang memudahkan sesetengah kerja yang remeh temeh:

Cth

Table

Filem(id, title, content, status_id )
Status(id, nama)

Dalam coding biasa, bila nak papar maklumat filem dan juga status, kita terpaksa buat  query seperti berikut:

select title, content, status
from filem
join status
   on filem.status_id = status.id

Mudah sahaja, tetapi, dalam laravel kita boleh skip, dan menjadikan coding kita lebih kemas. Cuma kena setup dulu relationship between model (belongsTo(), hasMany(), hasOne(), dll).

Lihat sample dibawah.

Model class Filem

public function getStatus()
{
return $this->belongsTo('App\Status', 'status_id');
}
Model class Status

public function Filem()
{
return $this->hasMany('App\Status', 'status_id');
}

Dalam view hanya masukkan kod berikut untuk dapatkan status

{{$parcel->getDistributor->nama}}

 

Filed Under: Technology Tagged With: array, eloquent, laravel, model, object, relationship

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

Cendol Terbaik Di Kuantan

Rojak Pak Lah Taman Gelora

Sarapan pagi di Arked Sri Gambut

Diet snack untuk abang-abang kacak

Coke Coffee Caramel ~ Not recommended!

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