Skip to content

Commit

Permalink
Refactor/store company data validation (#32)
Browse files Browse the repository at this point in the history
* create a middleware for authenticated users to be redirected to the dashboard once they access the /not-an-admin route (#27)

Co-authored-by: codejutsu1 <codejutsu@protonmail.com>

* moved the store company data validation rules to a request file

---------

Co-authored-by: Chidiebere Chukwudi <chidideveloper@gmail.com>
  • Loading branch information
codejutsu1 and jovialcore authored Jan 10, 2024
1 parent 1c9bbab commit 779b8a5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
7 changes: 4 additions & 3 deletions app/Http/Controllers/CompanyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
namespace App\Http\Controllers;

use App\Models\Company;
use Illuminate\Http\Request;
use App\Services\CompanyService;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Redirect;
use App\Http\Requests\StoreCompanyDataRequest;

class CompanyController extends Controller
{
Expand All @@ -35,7 +36,7 @@ public function create(): View
}


public function store(Request $request, Company $company): RedirectResponse
public function store(StoreCompanyDataRequest $request, Company $company): RedirectResponse
{
$this->companyService->storeCompanyData($request, $company);

Expand Down
37 changes: 37 additions & 0 deletions app/Http/Requests/StoreCompanyDataRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreCompanyDataRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => 'required',
'about' => 'required',
'url' => 'url|unique:companies,url',
'ceo_name' => 'string|nullable',
'cto_contact' => 'url|nullable',
'cto_name' => 'string|nullable',
'hr_name' => 'string|nullable',
'hr_contact' => 'url |nullable',
'logo' => 'required|mimes:png,jpeg,svg',
'source_slug' => 'nullable|string|unique:companies,source_slug'
];
}
}
13 changes: 0 additions & 13 deletions app/Services/CompanyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,6 @@ public function getAllCompanies(): array

public function storeCompanyData(Request $request, Company $company)
{
$request->validate([
'name' => 'required',
'about' => 'required',
'url' => 'url|unique:companies,url',
'ceo_name' => 'string|nullable',
'cto_contact' => 'url|nullable',
'cto_name' => 'string|nullable',
'hr_name' => 'string|nullable',
'hr_contact' => 'url |nullable',
'logo' => 'required|mimes:png,jpeg,svg',
'source_slug' => 'nullable|string|unique:companies,source_slug'
]);

try {
$companyData = $request->all();
if ($request->has('logo')) {
Expand Down

0 comments on commit 779b8a5

Please sign in to comment.