php leaf g:model Employee
<?php namespace App\Models; class Employee extends Model { // }
Az Employee modellt hozzákötjük a táblához.
<?php namespace App\Models; class Employee extends Model { protected $table = 'employees'; }
A működéshez szükség van az adatbázis modul telepítésére:
leaf install db
use App\Models\Employee; //... public function index() { $employees = Employee::all(); response()->json([ 'employees' => $employees ]); }
http localhost:5500/employees
//... use App\Models\Employee; //... public function store() { $employee = new Employee; $employee->name = request()->get('name'); $employee->city = request()->get('city'); $employee->salary = request()->get('salary'); $res = $employee->save(); response()->json([ 'success' => $res ]); }
//... use App\Models\Employee; //... public function update($id) { $employee = Employee::find($id); $employee->name = request()->get('name'); $employee->city = request()->get('city'); $employee->salary = request()->get('salary'); $res = $employee->save(); response()->json([ 'success' => $res ]); }
//... use App\Models\Employee; //... public function delete($id) { $employee = Employee::find($id); $res = $employee->delete(); response()->json([ 'success' => $res ]); }