2021-02-17 17:40:35 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Models\BusinessSector;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
|
|
class BusinessSectorsController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
2023-08-21 15:24:32 +02:00
|
|
|
$sector = BusinessSector::orderBy('order', 'ASC')->get();
|
2021-02-18 17:29:54 +01:00
|
|
|
$psectors = BusinessSector::orderBy('order', 'ASC')->get();
|
2023-08-21 15:24:32 +02:00
|
|
|
return view('bo.business-sector.index', compact('sector', 'psectors'));
|
2021-02-17 17:40:35 +01:00
|
|
|
}
|
|
|
|
|
|
2023-08-21 15:24:32 +02:00
|
|
|
public function saveDatas(Request $request)
|
|
|
|
|
{
|
2021-02-18 17:29:54 +01:00
|
|
|
$sector = $request->sectors;
|
2021-02-17 17:40:35 +01:00
|
|
|
|
|
|
|
|
for ($i = 0; $i < count($sector); $i++) {
|
|
|
|
|
if (isset($sector[$i]["id"])) {
|
2023-08-21 15:24:32 +02:00
|
|
|
$s = BusinessSector::findOrFail($sector[$i]["id"]);
|
|
|
|
|
$s->name = $sector[$i]["name"];
|
|
|
|
|
$s->order = $sector[$i]["order"];
|
2021-02-18 17:29:54 +01:00
|
|
|
$s->parent_id = $sector[$i]["parent_id"];
|
2021-02-17 17:40:35 +01:00
|
|
|
$s->save();
|
2023-08-21 15:24:32 +02:00
|
|
|
} else {
|
|
|
|
|
$s = BusinessSector::updateOrCreate([
|
2021-02-18 17:29:54 +01:00
|
|
|
'name' => $sector[$i]["name"],
|
|
|
|
|
'order' => $sector[$i]["order"],
|
|
|
|
|
'parent_id' => $sector[$i]["parent_id"],
|
|
|
|
|
]);
|
2021-02-17 17:40:35 +01:00
|
|
|
$sector[$i]["id"] = $s->id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $sector;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function create()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
|
*
|
2023-08-21 15:24:32 +02:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2021-02-17 17:40:35 +01:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function store(Request $request)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display the specified resource.
|
|
|
|
|
*
|
2023-08-21 15:24:32 +02:00
|
|
|
* @param integer $id
|
2021-02-17 17:40:35 +01:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function show($id)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
|
*
|
2023-08-21 15:24:32 +02:00
|
|
|
* @param integer $id
|
2021-02-17 17:40:35 +01:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function edit($id)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
|
*
|
2023-08-21 15:24:32 +02:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @param integer $id
|
2021-02-17 17:40:35 +01:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
|
*
|
2023-08-21 15:24:32 +02:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2021-02-17 17:40:35 +01:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function destroy(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$deleteOk = 0;
|
|
|
|
|
|
2023-08-21 15:24:32 +02:00
|
|
|
// check if there are Employees associated before deleting
|
|
|
|
|
// if (FaqQuestions::where('theme_id', $request->id)->count() > 0) {
|
|
|
|
|
// $deleteOk = 1;
|
|
|
|
|
// } else
|
2021-02-17 17:40:35 +01:00
|
|
|
if ($request->id !== null) {
|
|
|
|
|
$sector = BusinessSector::findOrFail($request->id);
|
|
|
|
|
$sector->delete();
|
|
|
|
|
} else {
|
|
|
|
|
$deleteOk = 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $deleteOk;
|
|
|
|
|
}
|
|
|
|
|
}
|