Get fuel types new fuel types

parent fd3d491d
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Fueltype;
use App\Models\Fuelcapacity;
use App\Models\Station;
class FuelController extends Controller
{
// This function for get Fuel Typespes
public function get_fuel_type(Request $req){
$fueltype = "";
if($req->id){
$fueltype = Fueltype::find($req->id);
}else{
$fueltype = Fueltype::all()->orderby('id','DESC');
}
return response()->json(['respond'=>$fueltype]);
}
// This function for create a new Fuel type
public function create_fuel_type(Request $req){
$message = '';
if($this->check_empty($req->name,$req->price)){
//create new User
$fueltype = new Fueltype;
$fueltype->name = $req->name;
$fueltype->price = $req->price;
$fueltype->save();
$message = 'Fuel Type successfully created';
}else{
$message = 'Type or Price cannot be empty';
}
return response()->json(['message'=>$message]);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment