Add backend operation to use with MyKad reader feature
This commit is contained in:
+8
-2
@@ -3,6 +3,7 @@
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Daerah extends Model
|
||||
{
|
||||
@@ -14,7 +15,7 @@ class Daerah extends Model
|
||||
* @var array
|
||||
*/
|
||||
// protected $fillable = [
|
||||
|
||||
|
||||
// ];
|
||||
|
||||
/**
|
||||
@@ -23,4 +24,9 @@ class Daerah extends Model
|
||||
* @var array
|
||||
*/
|
||||
// protected $hidden = [];
|
||||
}
|
||||
|
||||
public function negeri(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Negeri::class, 'kodnegeri', 'kodnegeri');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,12 @@ use Illuminate\Http\Request;
|
||||
|
||||
class DaerahController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$daerah = Daerah::on('mysql7')->with('negeri')->get();
|
||||
return response()->json($daerah);
|
||||
}
|
||||
|
||||
public function showOneDaerah($koddaerah)
|
||||
{
|
||||
$daerah = Daerah::on('mysql7')
|
||||
@@ -20,7 +26,7 @@ class DaerahController extends Controller
|
||||
$daerah = Daerah::on('mysql7')
|
||||
->where('kodnegeri','=',$kodnegeri)
|
||||
->get();
|
||||
|
||||
|
||||
return response()->json($daerah);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,17 +7,35 @@ use Illuminate\Http\Request;
|
||||
|
||||
class PoskodController extends Controller
|
||||
{
|
||||
public function showAllPoskod(){
|
||||
|
||||
public function showAllPoskod()
|
||||
{
|
||||
$poskod = Poskod::on('mysql7')->get();
|
||||
|
||||
|
||||
return response()->json($poskod);
|
||||
}
|
||||
|
||||
public function showOnePoskod($poskod)
|
||||
{
|
||||
$poskod = Poskod::on('mysql7')
|
||||
->where('poskod','=',$poskod)
|
||||
->first();
|
||||
->where('poskod', '=', $poskod)
|
||||
->first();
|
||||
return response()->json($poskod);
|
||||
}
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
|
||||
if (Poskod::where('poskod', $request->poskod)->exists()) {
|
||||
return response()->json('Poskod creation forbidden, already exist', 403);
|
||||
}
|
||||
|
||||
$created_poskod = Poskod::create([
|
||||
'poskod' => $request->poskod,
|
||||
'koddaerah' => $request->koddaerah,
|
||||
'kodnegeri' => $request->kodnegeri,
|
||||
]);
|
||||
|
||||
return response()->json($created_poskod, 200);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-4
@@ -7,15 +7,18 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class Poskod extends Model
|
||||
{
|
||||
protected $table = 'poskod';
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
// protected $fillable = [
|
||||
|
||||
// ];
|
||||
protected $fillable = [
|
||||
'poskod',
|
||||
'koddaerah',
|
||||
'kodnegeri',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
@@ -23,4 +26,4 @@ class Poskod extends Model
|
||||
* @var array
|
||||
*/
|
||||
// protected $hidden = [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user