|
|
@ -3,6 +3,7 @@ |
|
|
|
namespace App\Http\Controllers; |
|
|
|
namespace App\Http\Controllers; |
|
|
|
|
|
|
|
|
|
|
|
use App\Models\Company; |
|
|
|
use App\Models\Company; |
|
|
|
|
|
|
|
use App\Models\MenuCompany; |
|
|
|
use Illuminate\Http\Request; |
|
|
|
use Illuminate\Http\Request; |
|
|
|
|
|
|
|
|
|
|
|
class CompanyController extends Controller |
|
|
|
class CompanyController extends Controller |
|
|
@ -10,18 +11,22 @@ class CompanyController extends Controller |
|
|
|
public function add(Request $request) |
|
|
|
public function add(Request $request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->validate($request, [ |
|
|
|
$this->validate($request, [ |
|
|
|
'name' => 'required', |
|
|
|
'company_name' => 'required', |
|
|
|
'description' => 'required' |
|
|
|
'registration_no' => 'required', |
|
|
|
|
|
|
|
'template_id' => 'required', |
|
|
|
|
|
|
|
'is_active' => 'required' |
|
|
|
]); |
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
$data = $request->all(); |
|
|
|
$data = $request->all(); |
|
|
|
|
|
|
|
|
|
|
|
$data['created_by'] = $this->currentName; |
|
|
|
$data['created_by'] = $this->currentName; |
|
|
|
|
|
|
|
if(isset($data['base_url']) && $data['base_url'] != NULL) { |
|
|
|
|
|
|
|
$data['base_url'] = json_encode($data['base_url'], true); |
|
|
|
|
|
|
|
} |
|
|
|
$result = Company::create($data); |
|
|
|
$result = Company::create($data); |
|
|
|
|
|
|
|
|
|
|
|
if ($result) { |
|
|
|
if ($result) { |
|
|
|
return response()->json(['status' => 'success', 'message' => 'add Company successfully!', 'code' => 200], 200); |
|
|
|
return response()->json(['status' => 'success','data' => $result, 'message' => 'add Company successfully!', 'code' => 200], 200); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'add data Company failed!', 'code' => 400], 400); |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'add data Company failed!', 'code' => 400], 400); |
|
|
|
} |
|
|
|
} |
|
|
@ -51,6 +56,10 @@ class CompanyController extends Controller |
|
|
|
|
|
|
|
|
|
|
|
$data = Company::find($id); |
|
|
|
$data = Company::find($id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(isset($data['base_url']) && $data['base_url'] != NULL) { |
|
|
|
|
|
|
|
$data->update(['base_url'=>null]); |
|
|
|
|
|
|
|
$data['base_url'] = json_encode($data['base_url'], true); |
|
|
|
|
|
|
|
} |
|
|
|
if ($data) { |
|
|
|
if ($data) { |
|
|
|
$result = $data->update($request->all()); |
|
|
|
$result = $data->update($request->all()); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -71,6 +80,7 @@ class CompanyController extends Controller |
|
|
|
$data = Company::find($id); |
|
|
|
$data = Company::find($id); |
|
|
|
|
|
|
|
|
|
|
|
if ($data) { |
|
|
|
if ($data) { |
|
|
|
|
|
|
|
MenuCompany::where('company_id',$id)->delete(); |
|
|
|
$delete = $data->delete(); |
|
|
|
$delete = $data->delete(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'data Company not found!', 'code' => 400], 400); |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'data Company not found!', 'code' => 400], 400); |
|
|
|