lk.zachem.info/app/Modules/Main/Http/Controllers/Company/CreateCompanyController.php
Thekindbull 4a9f232723 - добавил авто-создание токенов в табл bx_id
- убрал политику на создание организации
2025-11-12 06:43:00 +08:00

54 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Modules\Main\Http\Controllers\Company;
use Illuminate\Validation\Rule;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Modules\Main\Models\Company\Company;
use Modules\Main\Models\Company\CompanyType;
use App\Models\Bitrix\SendCompany;
class CreateCompanyController extends Controller
{
/**
* Handle the incoming request.
*/
public function __invoke(Request $request)
{
$company = false;
$request->enum('type', CompanyType::class);
$validated = $request->validate([
'name' => 'required|max:255',
'email' => 'required|email|unique:companies',
'phone' => 'required',
'inn' => 'required|unique:companies',
'legal_address' => 'required',
'type' => Rule::enum(CompanyType::class),
'city_id' => 'required'
]);
$request->request->add([
'secret' => bin2hex(random_bytes(16)),
'status' => 'new'
]);
$data = $request->only('name', 'email', 'inn', 'legal_address', 'secret', 'status', 'type', 'phone', 'city_id');
try
{
$company = Company::create($data);
}
catch (\Exception $e)
{
if ($e->getMessage() == 'Error of bitrix identifier getter')
{
return back()->withErrors(['msg' => 'Не удалось отправить данные на проверку. Попробуйте позже'])->withInput();
}
return back()->withErrors(['msg' => 'Не удалось создать агентство. Попробуйте позже'])->withInput();
}
return view('main::company.created');
}
}